Monday, April 25, 2011

Hardware please give us a break

So, Hardware hasn't been nice to us. After our voice recognition circuit failed, we had to start working on a plan C while we are waiting for the PCB to arrive. We decided to try to add image feeding to our project. The idea is that the car would have a camera, that would take pictures. These pictures would be sent to the user controlling the car via the xBee connected to the car mBed. The xBee of the user would then get the picture data, send it to the mBed of the user, which would create an image file that the user would be able to see.

We managed to run a simple program to take a picture, and save it on a file. Of course, we had to give you a picture of ... Jefta Jawi, who loves being in front of the camera.

From Camera

Yes, he was posing for the camera.

But, at first we didn't go very past that. We had to find a way to send the image via the xBee, and then things started failing on us. Even our xBees that once worked fine, stopped working for awhile #don'tAskMeWhy.

New day, new trial, we got the xBees to transmit data once again. Yeah, I know. This just put us back where we were in the start, but it makes us happy to know that our xBees are not broken #hardwareFinallyGaveUsABreak.

Those of us who believe that late night coding is the best coding, you are RIGHT! Our program was tired of failing and we finally cut a break. We managed to have the mBed take a picture, save it on its local memory. Then, the file was open and copied to a second file. The proof is here:


Original Image


Image Copy


Yes, I know that this is just my lamp, but believe me: you don't want to see me on camera right now.

Now that we managed to open an image already taken and copy it into another file, we are ready to try to send the file via the xBee and writing it into the second mBed. Basically, most of our problems about writing into the file is that previously we were trying to hack the code to take the image, and send the file at the same time that it was being written #ABadIdea. So now open the file after it has being written seems to be a better option, since we will know the size of the packages that we are sending via the xBee.

Those who believe that late night coding is the best coding, should also believe that one needs to get some rest. Therefore, the xBee sending of the image will be left for tomorrow. If you are trying to take pictures with the mBed and the LS Y201 camera, here are some tips that really helped us:

  • Whenever there is a file being written to the file system of the mBed, it will disconnect from your computer. Whenever the mBed is done writing the program, meaning that a fclose is reached, it will reconnect to your computer automatically. If you don't see it come back, then move to bullet two.


  • If there are any bugs on your code and fclose is never executed, you will not be able to see the mBed again. Yes, I thought I burned the microcontroller #scary. In order to be able to see the mBed again, disconnect it from your computer, press the reset button and KEEP IT PRESSED. Then compile a new program that you know that works and connect your mBed to your computer. You will see the mBed again. Don't move your finger quite yet. Download the program into the mBed and then stop pressing the reset button. And voila, you can see it again. Make sure that you then debug your code to see why the file was not closed before putting it again into your mBed.


  • If you had a bug on your code, it is very likely that you opened it on the wrong mode (i.e. you opened as a read, and tried to write to it). Well, at least I did that many times.


  • The fact that the mBed keeps disconnecting is really annoying. Therefore, it was easier to create a txt file and print there everything that I would have printed if I had a print statement. Then, after the mBed is done (or after it fails), you can open the log file to see what happened.


  • If you are using the code showed in the example at the mBed page, you might not ever see your mBed connection again, since there is an infinite loop there. To be fair enough, we saw print statements on the terminal a couple times, but when we ran the code other times, we didn't see anything ebcause the mbed was disconnecting. I would recommend you breaking out of the while loop after you've taken a good number of pics, and then going back to your log file and seeing what happend.


  • mBed cookbook is your friend. And we are too! If there is something that you can't find there, reach out to us and we will try to help you if you can.
  • No comments:

    Post a Comment