EzDevInfo.com

raspberry-pi interview questions

Top raspberry-pi frequently asked interview questions

Any Java experience on Raspberry PI?

Is it possible to run average java app server on e.g. jboss or glassfish server on Raspberry pi? Any limitations? Does anyone have an experience in Java development for raspberry pi?

At least any appropriate JVM for RPi will be nice.


Source: (StackOverflow)

Raspberry Pi with Kinect

Could anyone get the camera data from the Kinect using a Raspberry Pi ?

We would like to make a wireless Kinect connecting it using Ethernet or WiFi. Otherwise, let me know if you have a working alternative.


Source: (StackOverflow)

Advertisements

Async raspberry pi gpio events in nodejs

I connected a button to the Raspberry Pi GPIO ports:

http://adafruit.com/products/801

The pi-gpio node js module allows only to pull the current status but not waiting for a state change:

gpio.read(16, function(err, value) {
    if(err) throw err;
    console.log(value);    // The current state of the pin
});

Is there any solution to bind events asynchronously?

In this example this would be whenever the button is pressed.


Source: (StackOverflow)

Hook up Raspberry Pi via ethernet to laptop without router?

I'm working on balloon project with a raspberry pi. When we potentially recover the raspberry pi, it will most likely be in a rural location and I'd like to turn off the pi at that point safely. Without a router or network nearby, I was wondering if there is a way to hook up a raspberry pi with an ethernet cable directly to a laptop?


Source: (StackOverflow)

Python AttributeError: 'module' object has no attribute 'Serial'

I'm trying to access a serial port with Python 2.6 on my Raspberry Pi running Debian. My script named serial.py tries to import pySerial:

import serial
ser = serial.Serial('/dev/ttyAMA0', 9600)
ser.write("hello world!")

For some reason it refuses to establish the serial connection with this error:

AttributeError: 'module' object has no attribute 'Serial'

When I try to type the same code in the interactive Python interpreter it still doesn't work.

Strangely, it used to work about a couple hours ago.

What could be the problem? I've tried to fix this for a while, installing pySerial again, rewriting my code, double-checking the serial port, etc.

Thanks in advance!


Source: (StackOverflow)

Cross-compiling Node.js for ARM6 (Raspberry Pi)

I'm trying to get node.js v0.7.9 to compile for the raspberry pi, but as node and v8 are quite large, I'm hoping to be able to cross-compile on another more powerful PC. I'm using the linux-x86 arm-bcm2708-linux-gnueabi toolchain from https://github.com/raspberrypi/tools and have used them to successfully build other executables for the system. I ended up setting the CC,CXX,CPP,STRIP,OBJCOPY,etc. variables to the toolchain equivalents in the environmental variables and ran configure with: ./configure --dest-cpu=arm --without-snapshot to get the final executable. Copying it over to the system and running it however produces the following error:

Extension or internal compilation error at line 0.
Segmentation fault

However, the segmentation fault doesn't happen for any of the non-javascript tasks like node --version and node --help. Are there any CFLAGS/CXXFLAGS I might be missing causing this problem? Bit confused....


Source: (StackOverflow)

Mono on Raspberry Pi

I've seen a lot of talk about running Mono/.NET code on the Raspberry Pi. Has there been any succceses in actually running any Mono code on the Raspberri Pi?

On their site, they list several Linux distributions that work on the device and some of these distributions include Mono. However, none detail whether Mono works on it.

Is there a working implementation?


Source: (StackOverflow)

How do I install dependencies when cross compiling haskell code?

I've successfully created a ghc cross compiler, that allows me to compile haskell code for armv6h (raspberry pi in my case) from my x64 linux machine. I've successfully run a hello world program on the raspberry.

No I want to build my real app, which has a lot of dependencies on other haskell modules. When I compile for x64 I simply do

cabal install dependenciy1 depenency2 ...

I know I could make my own programm a cabal-project an automate this step. But that's not the point here.

When I try to use the cross-compiler

arm-unknown-linux-gnueabi-ghc --make myapp.hs

It tells me about modules it could not find. Of course, they are not installed!

I read https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling and according to that I tried

cabal --with-ghc=arm-unknown-linux-gnueabi-ghc --with-ghc-pkg=arm-unknown-linux-gnueabi-ghc-pkg --with-ld=arm-unknown-linux-gnueabi-ld install random

random is the depenency I'm trying to install here. I get the following error:

Resolving dependencies...
Configuring random-1.0.1.3...
Failed to install random-1.0.1.3
Last 10 lines of the build log ( /home/daniel/.cabal/logs/random-1.0.1.3.log ):
/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804:      cannot execute binary file
cabal: Error: some packages failed to install:
random-1.0.1.3 failed during the configure step. The exception was:
ExitFailure 126

When I do

file /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804

I get

/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.10.2, not stripped

No wonder it can't execute it. It's compiled for arm.

Am I missing something here? My goal is to pull in all dependencies, then create a statically linked app that I can deploy on my raspberry.


Source: (StackOverflow)

Accessing the GPIO (of a raspberry pi) without ``sudo``

This question might not be specific to the raspberry pi, of course. Also, I'm relatively new to Linux.

I want to write a little library (in node.js, if that matters) to access the GPIO of the raspberry pi using the sysfs. However, accessing the sysfs requires sudo access, and that's bad for obvious reasons.

Quick2Wire seems to have a solution, but I want to understand it better and not just blindly use it. They've used C of course, but from what I understand, the code isn't complex, and probably can be pulled off with just bash, even if less elegantly. However, more than anything, I'm not sure why it works.

Any help will be great.

Edit: Thanks for the comments. It's clear I need to rephrase the question. Here goes: How is it that once installed (as root), the app doesn't require any more root perms to use? How does adding someone to a group help in this case? /sys/devices/virtual/gpio isn't the location where the gpio sysfs is available, so what's the trickery with that? I'm really a n00b, so these questions might be n00b-ish, so please bear with me.


Source: (StackOverflow)

Building a minimal Linux for Raspberry Pi [closed]

Now I got my Raspberry Pi. I am an experienced application software developer, but I've never done hardware stuff or low-level programming before. I want to build a minimal Linux, including drivers for all hardware on my Pi. For learning purpose, I don't want to install any pre-built Linux distribution on my Pi. Where should I start?


Source: (StackOverflow)

How do I open up my MySQL on my Raspberry Pi for Outside / Remote Connections?

I have a Raspberry Pi that stores temperature data for homebrewing activity. I am making a Spring MVC application on my computer and I want to tap the data. Both my Pi and my computer are on the local network. I can SSH and FTP into my RPi perfectly.

mysql --192.168.1.102 --u root -p db

Causes a "Can't connect to MySQL server on '192.168.1.102'".

My Java application isn't connecting either, obviously.

SHOW VARIABLES WHERE VARIABLE_NAME = 'port' ;

returns the default port, 3306.

Is there a setting that must be enabled to allow remote connections into MySQL?


Source: (StackOverflow)

Start Raspberry Pi without login [closed]

I would like to ask you if there is any way to start raspberry pi (using Raspbian) without login and password and to move directly to the GUI. Like Windows for example.


Source: (StackOverflow)

OpenCV VideoWriter will not open

I'm having trouble instantiating and opening an OpenCV VideoWriter for recording video on a Raspberry Pi (Raspbian Weezy).

My project is written in C++, but I've written a minimal Python program that demonstrates the problem.

https://gist.github.com/chriscollins/11ff2f43852e1c93dae8

Both my C++ code and the Python code above run without problem on my Windows machine. Sometimes the writer does not open, but that's to be expected - I don't have all of the listed codecs installed (the list of codecs comes from the Open CV source), but a good number of them work correctly. However, on a Raspberry Pi, both the C++ code and the Python code fail with the VideoWriter never being opened. In the above Python code, writer.isOpened() returns false for every single codec, when run on a Raspberry Pi.

I've chowned the destination directory to the user I'm running the Python script as, and chmodded it to 777 so I don't believe that it is a permissions problem. I think it may be connected with how I've installed OpenCV or some of its dependencies, but I'm not sure how to rectify it.

The install process I've used is as follows:

  1. Update firmware/packages via rpi-update, apt-get update and apt-get upgrade.

  2. Install the following dependencies via apt-get: libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev

  3. Download and unzip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip to /root/opencv-2.4.9.

  4. cd /root/opencv-2.4.9 and run cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_ocl=OFF. Output of cmake is available at https://gist.github.com/chriscollins/d8060e03a6acd6d4336c

  5. make and make install from the same directory.

Various other OpenCV functionality works correctly on the Raspberry Pi (in C++ or in Python) - e.g. viewing a webcam via VideoCapture, but I can't get the VideoWriter to work. I'm tempted to try installing FFMPEG from source instead of via apt-get, but as make takes 5+ hours to run on a Raspberry Pi, I was hoping I'd find the answer here, rather than proceeding with a trial and error approach!

Any advice on how to solve (or debug) this is appreciated.

EDIT: Added output of cmake command (https://gist.github.com/chriscollins/d8060e03a6acd6d4336c)


Source: (StackOverflow)

How to write a live data set to disk with async I/O?

I am new to developing in node.js (though relatively experienced at client-side javascript) and I'm running into lots of questions about good practices when dealing with asynchronous operations in node.js.

My specific issue (though I imagine this is a fairly general purpose topic) is that I have a node.js app (running on a Raspberry Pi) that is recording the readings from several temperature probes every 10 seconds to an in memory data structure. This works just fine. The data accumulates over time in memory and, as it accumulates and reaches a particular size threshold, the data is regularly aged (keeping only the last N days of data) to keep it from growing beyond a certain size. This temperature data is used to control some other appliances.

Then, I have a separate interval timer that writes this data out to disk every so often (to persist it if the process crashes). I'm using async node.js (fs.open(), fs.write() and fs.close()) disk IO to write the data out to disk.

And, because of the async nature of the disk IO, it occurs to me that the very data structure I'm trying to write to disk may get modified right in the middle of me writing it out to disk. That would potentially be a bad thing. If data is only appended to the data structure while writing out to disk, that won't actually cause a problem with the way I'm writing the data, but there are some circumstances where earlier data can be modified as new data is being recorded and that would really mess with the integrity of what I'm in the middle of writing to disk.

I can think of all sorts of somewhat ugly safeguards I could put in my code such as:

  1. Switch to synchronous IO to write the data to disk (don't really want to do that for server responsiveness reasons).
  2. Set a flag when I started writing data and don't record any new data while that flag is set (causes me to lose the recording of data during the write).
  3. More complicated versions of option 2 where I set the flag and when the flag is set, new data goes in a separate, temporary data structure that when the file IO is done is then merged with the real data (doable, but seems ugly).
  4. Take a snapshot copy of the original data and take your time to write that copy to disk knowing that nobody else will be modifying the copy. I don't want to do this because the data set is relatively large and I'm in a limited memory environment (Raspberry PI).

So, my question is what are design patterns for writing a large data set with async IO when other operations may want to modify that data during the async IO? Are there more general purpose ways of handling my issue than the specific work-arounds listed above?


Source: (StackOverflow)

Raspberry pi flashing LED issue - Python vs Java

i am trying to make an LED light flash on the raspberry pi using some code i found online ( i know - not the best but it was a tutorial site)

When i run the following python code the led light flashes;

import RPi.GPIO as GPIO
import time
pinNum = 4
GPIO.setmode(GPIO.BCM) #numbering scheme that corresponds to breakout board and pin layout
GPIO.setup(pinNum,GPIO.OUT) #replace pinNum with whatever pin you used, this sets up that pin as an output
#set LED to flash forever
while True:
  GPIO.output(pinNum,GPIO.HIGH)
  time.sleep(0.5)
  GPIO.output(pinNum,GPIO.LOW)
  time.sleep(0.5)

When i run the following Java code which is supposed to do the same - all i get to the console are the print statements which i have added - no flashing light

import com.pi4j.io.gpio.GpioController;  
 import com.pi4j.io.gpio.GpioFactory;  
 import com.pi4j.io.gpio.GpioPinDigitalOutput;  
 import com.pi4j.io.gpio.PinState;  
 import com.pi4j.io.gpio.RaspiPin;  

 public class ControlGpioExample {  
  public static void main(String[] args) throws InterruptedException {  
     final GpioController gpio = GpioFactory.getInstance();  
     final GpioPinDigitalOutput ledPin = gpio.provisionDigitalOutputPin(RaspiPin
.GPIO_04, "MyLED", PinState.LOW);  
     System.out.println("Started");
     try  
     {  
       while(true)  
       {
         System.out.println(ledPin==null);
         System.out.println("Looping pin now"); 
         ledPin.high();
         System.out.println("Set high called");  
         Thread.sleep(2000);  
         ledPin.low();  
         System.out.println("Set low called");
         Thread.sleep(2000);  
       }  
     }  
     catch(Exception ex)  
     {  
       gpio.shutdown();  
       ex.printStackTrace();  
     }  
   }  
 }  

Does anyone know why this might be? I think logically the should be doing the same thing - both are using the same GPIO pin number from the pi too

Thanks for your help


Source: (StackOverflow)