Making my own BirdTweeder

Some time ago I found an Instructable by quasiben about creating an image capturing bird feeder. I thought that would be a good way to start learning about Arduino because it implements so many different aspects... the basics from LEDs to Serial communication, to more complicated stuff like Xbees and writing external data. Believe it or not, a week or two of tinkering has been more eye-opening than almost a year of military avionics training. I'm pretty pleased with how much I've learned in 2 weeks. My electronics knowledge was limited to Ohms Law, and I'd never touched C/C++ before, much less custom circuitry, breadboards or microcontrollers.

I'm looking more for a push in the right direction so that I can learn this on my own, rather than for a "Here's the code" or a "It can't be done, n00b, leave the programming to the real geeks like me!" My searches of the boards and google have gotten me pretty far, but I'm at a point now where all of my searching keeps leading me to the same couple of pages that don't really help anymore.

I'll be totally honest, I learn by trial, error and experience (of which I have about 2 weeks), so if you're going to come at me with lots of stuff about bits, bytes, megaflops and ultramatrixpentahackolograms, odds are I won't have a clue what you're talking about. I just recently figured out why I can't just write 1's and 0's to a text file and save it as ".jpeg" and BAM have an image, if that gives you an idea of where I'm at as far as "theory" goes. However I've come a decent ways on this project and would like to see it through to completion. So if you have any ideas and can give me some pointers, I'd appreciate it.

So here is what I'd ultimately like to have. Not necessarily what I NEED to have, just what I'd like.

Lilypad Arduino, LinkSprite JPEG TTL Camera, Xbee installed in bird feeder outside, triggered by an IR sensor, powered by 3.7v Li-Ion battery (hopefully charged by solar)
When IR beam is broken, take a picture with the camera, and stream it to the Arduino in blocks of 8 bytes (I think 8 bytes?)
Arduino takes incoming blocks of JPEG data (starting with 0xFF 0xD8, ending with 0xFF 0xD9) and outputs them via Xbee to another Xbee inside the house
Indoor Xbee either directly (or through another Arduino) writes received data to a .jpeg file on a SD card, which is somehow hooked in to a digital picture frame for automatic/instant display.

I've gotten all of the above done except for the part of making sense out of the data that the Xbee receives. I monitor the Serial port of the Xbee connected to my PC and see the HEX data streamed in from the camera outside. I can send the data in HEX or BIN format, but neither of which am I able to just copy over to a text file and rename to .jpeg, obviously. So far I haven't even been able to tell if the pictures I'm receiving are corrupt or not. For this I assume I need some sort of Java, Python, C++ or some other super hacker script to take the BIN or HEX data and write it to a binary file? Or is it possible to write these streaming bytes straight from an Xbee or Arduino onto an SD card without needing a Java or third party program running on a PC to do the manual labor? Remember I'm not attempting to store the JPEG on the Arduino, I just want to use the Arduino as a means of transferring the streaming JPEG data from the camera outside onto an SD card inside.

Also of note is that I'm not expecting multiple pictures in, say, less than 15 seconds. In other words, if a bird comes along, I'll try to take a picture, take about 15 seconds or so to process it and send it inside and save it to disk, and then reset. So I'm not worried about overloading the Arduino or exceeding its memory capacity in that regard... my progress so far shows that this will be a non-issue with my implementation.

I'm kind of tinkering with the idea of giving this (when completed) to someone as a gift, and generally speaking I don't want to be like: "Here is your bird feeder camera, mom, now let me just teach you how to install and run Eclipse, JRE and SDK and how to monitor your serial port for incoming HEX data so you can manually, or by batch, convert it all into binary jpegs, save it to your SD card and then, every day, take that SD card to the digital frame in your living room to see the pictures!! HAPPY BIRTHDAY!!"

Know what I mean?

So anyways, I'm able to receive jpeg data on my indoor XBee from the outdoor camera. Right now the indoor XBee is hooked up to my PC, but I'd like it to be stand-alone with the digital frame and/or hooked up to another Lilypad Arduino, if need be. I'll tackle the hurdle of the Digital Picture Frame when the time comes for that, but for now, all I'm worried about is streaming JPEG straight from the Arduino outside to the XBee inside, to the SD.

The SD libraries I've found have shown ability to write text files and the like, but I haven't find a resource describing how to save a JPEG straight off of the Arduino or XBee. I guess the first thing I need to do is get a SD breakout or SD Shield, but am not totally sure where to start and/or if I even need a second Arduino, or if I can stream bytes straight from the XBee to an SD card as a JPEG in the first place.

Thanks for reading this far. Hopefully I've been clear enough. I'm not having any problems with code at the moment, so I've refrained from posting any (in large part it's similar to quasiben's, with a few additions to calculate a baseline IR reading to compensate for changes in ambience, some timing changes, and a potentiometer to control object detection sensitivity, which will be accessible from the outside of the bird feeder as a control knob).

In summary, I'm looking for ideas on the INTERIOR part of this project. I want to write Streamed data from a receiver XBee to a JPEG file on an SD card, which, if possible, I'd like to have connected to a digital picture frame, without the use of a third party interface/PC (but can use another Lilypad Arduino, provided it can inconspicuously attach to the back of the picture frame).

Thanks guys, this is a great resource.

I want to write Streamed data from a receiver XBee to a JPEG file on an SD card

Have you streamed a file from the serial port of a pc to the SD card on an arduino? If no, then that could be something to start tesing.

You mean just to get an idea of the process of writing to the SD card? If I'm going to do that, I might as well do it with the Serial output from the JPEG camera instead of the PC, since Serial is Serial pretty much, right? Like I said, I'm already able to get the data onto the receiving end of things (on the XBee), I just need to figure out how to process it from there.

Does that sound doable? Most importantly, I'm concerned with the feasibility of writing a JPEG on the SD with the HEX or BIN data that I'm streaming from the camera, without using any sort of PC-based processing. Everything I've read up until now has seemed to indicate that in order to write the binary jpeg file, I need to do some sort of pre-processing in Java or something like that in order to convert the data to a usable format.

I guess my next course of action is to get an SD shield or breakout, but I'm not sure what to get. Should I just bite the bullet and decide that this is going to, at the very least, be a 2-Arduino project, or does it sound possible that I'll be able to do it with just 1 Arduino, 2 XBees, and an SD board? I mean, I have a few Lilypads lying around, but I'm trying to be minimalistic with this, because if I give it as a gift, I'm going to want it to be as hands-off as possible so that all that has to be done is "plug it in" (read: wire it up) to some sort of modified digital frame, and have it do the rest.

Edit:

I just ran across this product from SparkFun: SparkFun JPEG Trigger - DEV-10549 - SparkFun Electronics

It pretty much simplifies the act of taking the picture and writing it to the SD card. It's not applicable to me aside from the fact that it writes the files to SD card. One caveat is that it writes them as .txt files and explicitly says they need to be renamed to .jpg in order to be viewed (although at least they are encoded correctly). I can't use it because my picture taking logic is going to be outdoors with my Arduino, and the saving/writing logic will be indoors, but that looks like it's in the right direction. I guess I could use the Arduino outside to trigger an event, send (via XBee) notification to the interior JPEG Trigger, which will then send (again, via XBee) the commands to take and retrieve a picture, which will (... again, be transmitted via XBee) back inside to the JPEG Trigger for processing/saving to JPEG.

Doesn't solve the problem of having to manually rewrite the .txt files to .jpg, and that seems like a TON of unnecessary back and forth, especially when I've already got the camera taking and sending image data indoors. I don't want to reinvent the wheel, but my method seems to be working fine as is. Simplifying it to use the JPEG Trigger, I think would only over-complicate it in my case.

I'm going to purchase a MicroSD Breakout, SD Breakout, the SparkFun MicroSD Shield, and the Adafruit Data Logging Shield. Not sure which of these I would end up using, but will be good to have them to learn on, regardless.

And of course, I still welcome any help or suggestions on what direction to go in...

Sorry, but you just ramble too much for me to be of any help.

Yeah, it's called reading. I know it must be tough dude. If it's not too much trouble for you to step off your pedestal (I know how tiring that can be too... especially having to step all the way back up), you're still welcome to help.

Or I guess I could make it easier for you.

Me want save data to plastic thingy for pretty pictures of birds.

exxpi:
Yeah, it's called reading. I know it must be tough dude. If it's not too much trouble for you to step off your pedestal (I know how tiring that can be too... especially having to step all the way back up), you're still welcome to help.

Or I guess I could make it easier for you.

Me want save data to plastic thingy for pretty pictures of birds.

Forum meltdown alert! :slight_smile:

Exxpi, you have data coming in to the PC and want to 'get the picture'?

If your data is supposed to be a jpeg or other picture file then you only need some PC code to open the serial channel to the XBEE, open a file on the PC (named properly, if it's a jpeg then it should be named something.jpg) and store the bytes in the file. Get one pic across and then see if you can view the file by double-clicking on it or opening it in a graphics viewer like whatever came with the camera -- that should handle the format from the camera, hey?

You can get Gnu C++ free for your PC or use some other programming tool to write the PC code. It's going to be simple code as it doesn't have to do much but expect a couple more weeks with your eyes open and typing across the internet.

@#$&, you got this far! Of course 'this far' might be 'lost in nowhere' if the pictures aren't actually coming across the XBEE. You have -data- but until you see picture you don't know what you have.

In future you will need to 'do the SD on Arduino thing' if you want to go stand-alone. I don't see why not put the SD out with the camera and just change SD chips now and then (as in why bother with the XBEE for this?) but you have what you have. Truth is, I would have the camera inside with the PC and only use the Duino as a bird detector and signal device rather than out where stuff can get on the lens and weather may get to it, but that's me.

Thanks, it's nice to get actual support on a support forum instead of just getting trolled :roll_eyes:

That said, I see what you're saying about writing the JPG on a pc. Shouldn't be too hard for me to do, at least to verify that my pictures are being captured and transmitted correctly.

You said I'd have to use SD and Arduino -- is that to suggest that there really is no way to write jpgs to SD using just the XBee and the serial data it gets streamed to it from the camera outside? Probably a dumb question.

Is that also to suggest that i should be able to write a jpg straight to the SD from another Arduino without having to worry about renaming it on a PC? I had read that tge Arduino SD lib could write bin files bit had to save them with a .txt extension, which wouldn't be usable on a digital frame.

I want this to be hooked up to a digital picture frame and require no human interaction to save and display the pictures... which is another reason i don't want to have the SD outside with the camera. I'm making it for someone even less savvy than myself and don't want them to have to tinker with it.

Thanks man your suggestions are appreciated.

You said I'd have to use SD and Arduino -- is that to suggest that there really is no way to write jpgs to SD using just the XBee and the serial data it gets streamed to it from the camera outside?

No I didn't because you don't have to. It might make sense to put the SD outside and with some more info it might not. Like, do you have power going to the feeder? Compared to Arduino, camera is power-hungry and flash might be too, the SD is flash.

Is that also to suggest that i should be able to write a jpg straight to the SD from another Arduino without having to worry about renaming it on a PC?

Yes, you write the file to a usable name on the PC the first time and if the data is good the file is good. The Arduino is just passing data, there is no file name there. A file is just a container for data. Your PC program gives it a name, like maybe a date/time stamp.jpg. The name is just there to make it easy for programmers to separate what from whut and find their good stuff later.

I want this to be hooked up to a digital picture frame and require no human interaction to save and display the pictures...

Maybe you have a digital frame that can take signal directly from the PC? I have an old one that can read directly from a USB host via cable ... as far as I know the Arduino is not up to being a USB host. Maybe you have or can get a wireless digital picture frame?

GoForSmoke:
No I didn't because you don't have to. It might make sense to put the SD outside and with some more info it might not. Like, do you have power going to the feeder? Compared to Arduino, camera is power-hungry and flash might be too, the SD is flash.

Good point. Camera, Lilypad and XBee are running fine off of a 3.7v Li-Ion at the moment. I'd like to have it solar eventually, but sounds like power consumption is just another reason not to have the SD hooked up outside with it.

Yes, you write the file to a usable name on the PC the first time and if the data is good the file is good. The Arduino is just passing data, there is no file name there. A file is just a container for data. Your PC program gives it a name, like maybe a date/time stamp.jpg. The name is just there to make it easy for programmers to separate what from whut and find their good stuff later.

I haven't gotten my SD stuff in the mail yet, so can't tinker with it, but I did manage to get a Java app running to read the data straight from the XBee (connected via USB) as it is streamed in and write a JPEG with it (monumental achievement for me). The JPEG has a few corrupt bits which kind of suck and maybe I can figure out how to fix, but all in all, the data is getting through. The caveat is that this assumes the end-user will have to have the XBee hooked up via USB as well as capability to run the Java monitor.

So I still need to figure out how to get the receiver XBee hooked up to another Lilypad and still be able to transmit data through to the Java app. Newbie problem, but I can't even figure out which pins are hard serials (Rx/Tx) on the Lilypad Simple board... they're labeled on the standard Lilypad, but not on the Simple Board, as it has fewer pins.

Once I can get the Java app reading the XBee through the USB-connected Arduino (instead of straight from the XBee), it'll be on to writing to SD.

Maybe you have or can get a wireless digital picture frame?

That's a good idea. Obviously this is becoming too expensive to have any real practicality to it, but as a gift and as a learning experience, it's not a bad project. If I can get a wireless frame, could I use an ethernet shield + SD card combo, hooked straight to an ethernet port on the switch/router, and then just point the wireless frame to the directory of the SD card?

In other words, if I have the files written to the SD on the arduino, and hook it up to the router, can other devices access the SD card as if it were just another shared drive on the network? Sounds like that'd be the way to go, and would save me from having to crack open a digital frame and mess with the insides.

Thanks a lot for all of the good ideas... definitely got me going in a good direction I think.

In your process you have weak point to work with/around and I only have some suggestions.

The radio is a weak link as you are getting corrupt bits but it has the fine remote comms ability. One way around is sending data in packets that include check data. If a packet is received that checks as bad, it is requested to be re-sent. Even single bytes are sometimes sent with an extra 'parity bit' that makes the total number of set bits even or odd, at the receiving end a bad character can be caught on average at least (always if only 1 bit is bad) half the time and then usually the whole message is re-sent. Another solution is sending check-and-correct data which there ain't room to really discuss here, but it requires extra data transmitted and re-transmission of packets so badly gone that the correction data is not enough.

The simplest way is to keep the picture at the send end and re-transmit on error and that does require check data to be sent. Between that, power and environment, I would keep the camera inside (that's why there's telephoto zoom) hooked to a PC of some sort and not bother transmitting except perhaps to the picture frame. That would also allow large pictures and video.
You don't want to dedicate a whole PC? Do you know how little you need to make a PC work? Box, power, mobo with CPU and minimal RAM, keyboard and minimal screen for convenience, and one or two USB flash drives covers the bill if you're willing to use a boot-and-run from USB system. Puppy Linux that loads to and runs Fast in RAM is a good choice, a mobo with 256M RAM (yes 1/4 Gig and probably half that is enough) can run well on it.
Just about any old PC made in the last ten or so years can boot from USB -- the parts don't have to be new. Just look for old but not too old, sometimes sitting out by the curb, and do some salvage work to see what you got. Stripped down, a PC doesn't even use a whole lot of power. Set it up to suspend and wake on input (without disk drives to spin up they wake up quicker) from keybd, usb or serial and it only sucks wall juice when it's at work.
Do you have a Pennysaver or Craig's List?

On another note.. if the cost of Arduinos is a concern:

Note you don't have to use the Tiny chips, a 328 as stand-alone can be done using the same basic way. I would recommend using a socket for the MCU instead of soldering directly to the chip pins. And if you don't have a lot of pieces to connect then hehehe, maybe two sockets (one for the chip and maybe one for the bits) is all you need instead of a proto-board or PCB. Of course you might also get crucified by real electrical engineers.

Here's a link to that MIT page if you are interested in using ATtiny chips, it's got the software download link:
http://hlt.media.mit.edu/?p=1229

Thanks for all of the excellent suggestions. I think all of the stuff you mentioned in your second post is beyond my depth right now... one step at a time :slight_smile:

I did however take your other post to heart, and wrote some error/data validation stuff to ensure the packets are received correctly. 9 out of 10 pictures come through with no lost or corrupted bytes now.

I'm still waiting on my SD card components/shields to arrive so I can start experimenting with that and saving the data on the receiving end, however for now my Java app is serving its purpose.

Two things remain an issue:

1.) I'm still planning on giving this as a gift, which means I don't want the end user (my mother) to have to worry about hosting a Java app, setting up/running a spare PC to receive the data, etc. I do agree it's simple enough to put together a spare PC, but that's something I don't want her to have to worry about.

2.) Making updates to this software will be tricky once the Arduino and XBee are installed in the bird feeder, so I'm researching if I can possibly upload sketches to it wirelessly through my XBees. Ladyada had a tutorial on it, but so far it's not working for me -- possibly because my Sketch needs everything (XBees and Camera) running at 9600 baud. I can get the Arduino to reset remotely, but so far my sketches aren't actually getting transferred.

Is wireless uploading of sketches still a possibility with Arduino 1.0? I read somewhere that all of the wireless upload guides were outdated and no longer applicable.

once it's set, I dont see why you'd need to revise the sketches?

If your Java applett is converting the data over to a jpeg correctly, see if there's a C++ version of that same Java code. I bet you there is :wink:

The hard part is getting the picture displayed. Wondering if a VGA shield (gameduino?) and a 13" LCD monitor off ebay wouldn't be better? Provided you could use the Sd as a buffer between saving the file and displaying it to screen?

magnethead794:
once it's set, I dont see why you'd need to revise the sketches?

Well, I'm pretty new to this, so I'm guessing that there will be bugs that need to be squashed after it gets "deployed." The wireless update will be a really nice feature if it's possible, but otherwise I'll just have to be clever with how I place the stuff inside so that the jacks are all accessible easily.

If your Java applett is converting the data over to a jpeg correctly, see if there's a C++ version of that same Java code. I bet you there is :wink:

Forgive the noobishness, but with C++ I would just have a .exe that I could give her to run? I've never programmed a windows app or anything C-related outside of Arduino. Would be cool if there were a system tray icon that flashed every time a picture was captured outside :slight_smile:

The hard part is getting the picture displayed. Wondering if a VGA shield (gameduino?) and a 13" LCD monitor off ebay wouldn't be better? Provided you could use the Sd as a buffer between saving the file and displaying it to screen?

I'll have to look in to that. I was thinking that maybe I'd just crack open a wireless frame and solder the internal SD connectors from it onto my SD shield instead. Pretty much the same thing, isn't it? They all share the same connectors from what I'm told, so if I hooked a little Arduino (like a Lilypad) up to the frame and instead of soldering the SD adapter onto it, just hook the leads up to the frame's SD connectors. I know the digital frame they have now just automatically reads from a SD card when it's inserted.

exxpi:

magnethead794:
once it's set, I dont see why you'd need to revise the sketches?

Well, I'm pretty new to this, so I'm guessing that there will be bugs that need to be squashed after it gets "deployed." The wireless update will be a really nice feature if it's possible, but otherwise I'll just have to be clever with how I place the stuff inside so that the jacks are all accessible easily.

I would do the latter. Actually, if you can bench-test it, yo'll find that bugs will be ew and far between. Or maybe I've just gotten lucky with my projecs?

If your Java applett is converting the data over to a jpeg correctly, see if there's a C++ version of that same Java code. I bet you there is :wink:

Forgive the noobishness, but with C++ I would just have a .exe that I could give her to run? I've never programmed a windows app or anything C-related outside of Arduino. Would be cool if there were a system tray icon that flashed every time a picture was captured outside :slight_smile:

If you're going to be displaying the images on an external display, why do you need an application running on a host computer? Should be able to make the arduino do everything the java does........

The hard part is getting the picture displayed. Wondering if a VGA shield (gameduino?) and a 13" LCD monitor off ebay wouldn't be better? Provided you could use the Sd as a buffer between saving the file and displaying it to screen?

I'll have to look in to that. I was thinking that maybe I'd just crack open a wireless frame and solder the internal SD connectors from it onto my SD shield instead. Pretty much the same thing, isn't it? They all share the same connectors from what I'm told, so if I hooked a little Arduino (like a Lilypad) up to the frame and instead of soldering the SD adapter onto it, just hook the leads up to the frame's SD connectors. I know the digital frame they have now just automatically reads from a SD card when it's inserted.

This I don't know for sure.....but I'm pretty sure that you can't simply connect them in this manner...

Thank you for the tips. Have been hard at work with this project and am making progress. Still not sure what to do on the receiving end as far as displaying on a picture frame goes, but maybe I'll bite the bullet and just use a host PC. My SD shield finally arrived and I plan on messing with it this weekend. In the meantime I've started to assemble the actual enclosure and piece things together.

I have the battery and solar cell linked up and powering my Lilypad and can send pictures from across the room to my XBee hooked up to the PC. Very cool.

In assembling the bird feeder housing (it is made of wood), I'm running into the dilemma of how to waterproof the exposed components. I'm going to have 3 items exposed: The camera, which will have a hole cut into the side panel for it to stick out of, a reset switch, also cut into the rear wood panel so it can be reset without having to crack the whole thing open, and lastly, a VCNL4000 proximity sensor (approx 1.5"x1.5"), which has to have at least part of its surface exposed in order to work.

Would clear epoxy work for this purpose? Could I install the proximity sensor into the side panel of the bird feeder, and then cover it up and seal the cracks with epoxy? Is epoxy transparent to IR light (I'll just Google that one), and will it interfere with any of the soldered connections or chips?

plexiglass is your friend. $5 at home depot. Make sure you get a jigsaw blade meant for plastics. Silicone the edges where you bolt it (use machine screws, not wood screws) to the wood, and you'll be all set. Maybe add a eve so that the lense doesn't get spotted from rain.

Not sure on proximity sensor.

I suppose you could forego the plexi and just make a 3-walled hut with long sides to keep the rain out, not sure how well it'd stay dry though.

If you're converting the picture on computer, why can't you convert it on the arduino before you send it to the computer? Rather than send the photo to the computer, have java clean and fix the file, and send the file out, do it on the arduino board. Send the file to SD, then open it and apply changes, then save it. The SD card is basically a hard drive for the arduino. Anything you can make java or python do, C++/arduino can do.

This is a very interesting project.

It has many of the feature and subjects that I'm going to be tackling soon also.

Was wondering if you saw this thread...
http://arduino.cc/forum/index.php/topic,15184.0.html

The company website : http://www.eye.fi/

Would that fit into your image transmit function?

Gaver

Hi, did this project get completed.

I am trying to do something similar -

Uno board with a micro SD card on a shield and then a real time clock attached.

I then want to attach a transmitter and receiver with IR beam. Every time an object passed the 'beam' I would like a recording to the SD card - just in time format. Do you think this is easy for a complete newbie?