Wireless Communication
To interface with the FONA 800 on our Teensy++ 2.0, we used the Adafruit FONA Arduino library. The initial part of our script was simply setup for the FONA, as provided in the Adafruit examples. The setup consisted of retrieving the FONA model, providing the FONA with necessary credentials, and turning the GPRS subsystem off and back on again. The second part of our script is the post function, which first "posted" (actually by using HTTP GET) our data to a dweet.io page labeled "birdbrainz." Meanwhile, our Freeboard was using this dweet.io url as a datasource to update its data. Below, you can see both our code and our data visualization on Freeboard.
Motion Detection & Image Capture
Adafruit also provides a library for our TTL Serial JPEG Camera. With it we were able to reliably detect motion and capture images. We split up these tasks into different methods, that you can see in the code below.
camera_setup() initializes the camera by checking for an available SD Card to have something to store the images, setting up a serial connection to the camera, setting the image size and activating motion detection.
capture() takes a picture and writes it in junks of 32 bytes each over SPI onto the SD Card.
check_motion() just returns the value of motionDetected(), a function provided by the Adafruit library that returns true, if there is motion detected between now and the last call of motionDetected().
camera_setup() initializes the camera by checking for an available SD Card to have something to store the images, setting up a serial connection to the camera, setting the image size and activating motion detection.
capture() takes a picture and writes it in junks of 32 bytes each over SPI onto the SD Card.
check_motion() just returns the value of motionDetected(), a function provided by the Adafruit library that returns true, if there is motion detected between now and the last call of motionDetected().
Data Collection
To collect all the data of our sensors, we wrote the functions shown below. As our temperature and humidity sensor is also from Adafruit, we were able to use their library for the sensor as well.
sensor_setup() just starts the communication with it over I2C.
get_temp() and get_humid() return float values for temperature and humidity by calling the appropriate function of the library.
get_weight() reads the raw value returned by our force sensitive resistor (FSR). It then translates that voltage reading to grams by using the function provided in the FSR's datasheet.
sensor_setup() just starts the communication with it over I2C.
get_temp() and get_humid() return float values for temperature and humidity by calling the appropriate function of the library.
get_weight() reads the raw value returned by our force sensitive resistor (FSR). It then translates that voltage reading to grams by using the function provided in the FSR's datasheet.
Food Dispensing
For dispensing food we modified a standard servo motor like shown in https://learn.adafruit.com/modifying-servos-for-continuous-rotation/breaking-bad-barriers to set it up for continuous rotation. Code wise we then used the Servo.h library (again provided by Adafruit :) to write the following dispense() method.
It creates an object for the attached servo and triggers its motion by writing any value to it. Then it waits for 3 seconds, which turned out to be a appropriate amount of time for the archimedes screw to push around a handful of food out onto the front plate. After that it just detaches the servo object again.
It creates an object for the attached servo and triggers its motion by writing any value to it. Then it waits for 3 seconds, which turned out to be a appropriate amount of time for the archimedes screw to push around a handful of food out onto the front plate. After that it just detaches the servo object again.