I need the Raspberry Pi in the balloon to act as a slave, waiting for commands from the master on the ground. The LPRS easyRadio Python example seems to sit in a loop waiting for keyboard entry, it only prints received data after it sends data, or the command flush is sent. If I have missed something then I apologise, so I decided to write my own code.
I took delivery of the new Rasperry Pi 2 and spent the last few days setting it up. I started with a clean install of Raspian and that has had an upgrade, the desktop looks good now. It’s difficult to say if it feels any faster than my B+ but I have not had much time to try it out.
As the easyRadio software is written in Python I decided to use the Python PiCamera software, I did the usual update then tried to install picamera, but I was told I had the latest version. However, when I tried to use the camera it generated an error report that ended in this unit can only be used on a Raspberry Pi! Now I don’t know if this is something to do with the Raspberry Pi2 or the new version of Raspian, but I decided to use Raspivid and Raspistill instead. These have to be called through os.system, I may come back later and look at this, but for now everything is working as I wanted.
The programme sits in a listen ending loop waiting for an input, once it is received the variable incomming holds this data. The easyRadio sends data in packets of 180 bytes and as I only expect to receive short messages only up to 180 bytes is read from the Serial Buffer. I also decided to use capitalisation for commands, it’s not necessary but I thought it might stop commands being sent accidentally. Once incomming has a command it is compared with the list of commands and the correct command routine is called. At the moment PRINT takes a single photograph, VIDEO takes a short video, GPS turns on the GPS and transmits the data back to the ground. STOP shuts the programme down.
GPS has not yet been implemented as I am not sure if I will use an Arduino to gather sensor and GPS data that is then sent over a serial line to the Raspberry Pi for transmission to the ground. The command set can easily be expanded. The programme sends a Balloon ACK back to the ground to show it received the signal.
I have not been able to test the range yet, but I hope to be able to test that during the coming week. The Python code is shown here for Python 2, I can’t say if it will work in Python 3, that’s something else to try.
# easyRadio slave unit. this unit is mounted on the balloon
# it sits in a receive loop waiting for commands
# Chris Rouse February 2015
"Takes a single photograph"
os.system("raspistill -vf -hf -o 'image.jpg'")
"Takes vide for numSecs seconds"
os.system("raspivid -o 'video.h264' -t 3000")
"Starts the GPS"
"Shuts this program down it cannot be restarted over easyRadio"
# set up the serial port, this will be ttyUSB0 for the easy radio
ser = serial.Serial("/dev/ttyUSB0", 19200, timeout = 0.5)
# main loop
numbytes = ser.inWaiting()
incomming = ""
if numbytes >0: # wait for a singnal to come in
# easyRadio sends up to 180 characters
incomming = ser.read(180) # read in up to 180 characters
if incomming != "":
# now check for commands
if incomming == "PRINT":
print("Takes a single picture")
if incomming == "VIDEO":
print ("Takes a video")
takeVideo(60) # change this value to suit, this is 1 minute
if incomming == "GPS":
print("Starts collecting GPS data, and send back live data")
runGPS() # could add a time to run here
if incomming == "STOP":
print("WARNING this stops communications")
# end of commands
incomming = "" # reset text string
# now send ACK to master unit to show the command was received
ser.write(">>> Balloon ACK\r\n")