Thursday, December 5, 2013

Updates to the Christmas tree project

I made a handful of modifications to my Christmas tree this week! Using shift registers I eliminated most of the wires connecting the Arduino to the LED display. Programmed a few scrolling patterns and select between them randomly. And I neatened up the wiring a little bit, so the whole thing is not quite so ugly.




Seems to be a couple deficiencies though... I think its due to the way I tied the shift and latch clocks together, but I am not able to get the top row of my tree to light up. And I would love to make it battery powered and wireless and hang it on my actual tree. Might be a bit ambitious for now though, and would require taking apart one of my older projects which I don't know if I want to do yet.

Saturday, November 30, 2013

Christmas tree! Engineer style

Its the last weekend of november, and that means time for a Christmas tree. But, since I don't own one, I had to make one -- LED style!

First I laid out 27 LEDs in the shape of a tree. Didn't have all the same color or size, so had to be a bit mismatched. Also discovered that my camera does not like to autofocus on protoboard... must be all the little holes messing it up.



Step 2 was wiring. Each LED got two wires, one for cathode and one for anode. Tried to keep all the cathodes orange for distinguishing them later.



Third, I divided up the wires into rows and columns of the tree. This way I could individually address each LED in a logical manner. I used the Anodes for the columns and cathodes for rows.

Fourth I connected them to the digital pins 0-13 on my Arduino (I had 6 columns and 8 rows) and loaded some code from the Arduino Cookbook. Christmas is here!!!





Wednesday, October 16, 2013

Sensor readings

Finished the first iteration of code for capturing Roomba sensor readings. Now I have a function that can be used to access each individual sensor on the Roomba. I have some ideas to increase the speed of accessing the sensor values, right now it is quite brute force and wasteful, but it seems to work. The code posted includes some demo functions for outputting each sensor package. Code is available from my repository and a sample screenshot is given below:


Monday, October 14, 2013

Roomba Arduino Library

Haven't done much on any of my electronics projects over the summer, but I pulled my Roomba out of the storage closet this weekend to see if it was still capable of vacuuming a floor. Probably no thanks to all the modifications I had tried to do to it (see my previous posts), it turned off about a second after starting, but I was able to get the serial port to accept commands. Eventually I may try to write my own vacuuming routines for this, since the existing computer seems to be unhappy about something, but for now I've just been working on compiling a library for Arduino out of the Roomba SPI.

The result is the project I started (google code link). You can checkout with mercurial (once I get a more complete library I'll package it a bit better and write an API). So far LED and motor functions are included.

After the break are a short video and photo of the setup

Tuesday, June 25, 2013

Potentiometer and Next Photo Timer

I installed my potentiometer today, connecting it to the A0 analog input pin. It is used to select the time between consecutive photos. The way I have set it up, the analog values are mapped to times between 45 and 90 seconds. During photo transfer, the elapsed time since the photo was captured is recorded, and subtracted from the potentiometer "time" to tell the user the "Time until next photo". The time can be selected and changed during or after transfer by the user. The implementation was quite straightforward, though the number of wires hanging off the breadboard and Arduino tells me its getting nearly time to get a case set up for this thing! The photo below shows the potentiometer and updated LCD display... which is also getting full... might have to start scrolling or switching between 2 displays to fit all the information I want to show.


Saturday, June 15, 2013

LinkSprite library

I finally have most of my linksprite camera functions working, so I have migrated them into their own library inside of my code repository. Of course there are bound to be some bugs, if you find any, please do let me know, best would be with the issue tracker in the repo.

On the hardware side, I added a toggle switch that makes my life substantially easier when reprogramming the Arduino. Previously I would have to remove 2 jumpers on the XBee shield, so that the computer could talk to the microcontroller to reprogram its memory. Now, the switch (see photo below) allows me to easily select between the connected and disconnected states.


Next few times I work on the code, I will probably be fixing bugs with my library, and general issues in my issue tracker. Soon I do want to connect the DIP switches though. And I'm always looking for ideas on how to improve my transmission rates because that is the single easiest way to get my battery life to increase.

Wednesday, May 22, 2013

LCD character screen and photo resolution

It seems every day that my list of issues on my google code issue tracker are always increasing, or at least never decreasing. But I got a few knocked off or at least reduced in severity over the last couple days.

To reduce power consumption I used my DMM to study which parts of the system used the most power, and to validate the power savings mode on the camera. What I found:

  • Entire system was using 280 mA at the start of my fixes.
  • The power LED was using almost 13 mA, so replacing the resistor in series with the LED brought that down to 3 mA. Further savings might be made by flashing the LED instead.
  • The IR LEDs were always on, using about 140 mA of power. I replaced the photocell with a 1K resistor which made the system think it was always light, and turned the IR LEDs permanently off.
  • The power savings mode was not initially working, but a delay in the code fixed that. During power savings, the camera uses 50 mA, and during normal mode it uses 70 mA. 
  • The XBee uses 70 mA. There is some sort of cyclic power savings mode that might be applicable for my application, but the effort in implementing it does not yet justify it. 
Overall I managed to reduce my power consumption to about 40% of its original, which should extend the battery life nicely. 

Another feature I wanted to implement is a higher resolution photo mode. This was actually quite trivial, and just consisted of another command sent to the camera during startup. However I had a small bug to sort out: the files became longer than 2^16 bytes, meaning I could not use a 'word' to store the location of file I was currently reading. 

Adding an 16x2 LCD character screen was also remarkably easy with the LiquidCrystal library. The sample code was easy to implement, and now I can operate my camera basestation without needing a computer which is a huge bonus. The LCD character screen takes care of providing user feedback and indicating which photo is currently being captured, and how long is left in the transferring process.

Later I will add a couple photos and video of the system in action: I turned a couple plant pots around and I'm hoping to capture the plants turning back towards the sun over the course of the day. It will be a good test of how the battery is holding up as well.

Sunday, May 19, 2013

Issue trackers and Arduino serial buffer sizes

This week I started using the issue tracker that came with Google Code, and I really like it. Its a much better way of keeping track of my outstanding tasks than my whiteboard or keeping them in my head.

One of the main issues I identified was extending the battery life of the wireless unit. Currently I can take about 300 photos, which at 30 FPS means 10 seconds of time lapse video. Not great. I thought of a couple ideas that could help me here:

  1. Power savings mode when the camera is waiting between frames
  2. Faster data transmission so the camera is in power savings mode for longer
  3. Hardware modifications like disabling the IR LEDs

Power savings mode was fairly trivial to implement, it was just 2 commands I sent over serial to turn on or off the camera's power savings mode. Next I worked on the transmission speed. My first thought was to decrease the "interval time", or time between successive frames, but this started causing data transmission errors. So instead I worked on increasing the buffer size, so that more data was transmitted at once. However, the microcontroller only appears to have a serial buffer of 64 bytes, so when I tried to get more data than 56 bytes per frame, I was running into problems (due to the 5 extra bytes before the frame starts). What I ended up doing was removing the delays in my code, and implementing a loop to poll the receive buffer. In case of transmission errors, I also added a timeout, and flag that was set upon an unexpected frame size, which caused the erroneous frame to be resent. At the end, it was something like this:


// loop continuously until the data is ready
while(!Serial.available()){
  delay(1);   // 1 ms delay
  timeout++; // timeout counter
  if (timeout > TIMEOUT_MAX){ // if 1000 ms pass before data received, assume erroneous data
    i = 5;  // satisfy exit condition
    ResendFlag = 1;  // ensure data is resent since erroneous
    break;
  }
}
// if we get here, data is available so process it


This had some pretty good results, my transmit time was reduced by almost half. Now I'm running an endurance test to see if it actually improves my power consumption, and if so by how much.


Friday, May 17, 2013

A summary of progress and next steps

Over the last week or so I've made some pretty good progress on the time lapse camera. From a fully charged device, I can shoot a 327 frame video (see below), which lasts about 14 seconds.



After the break I'll summarize progress so far, as well as the next steps I plan on doing. My philosophy is to finish each section completely before moving onto a new task, limiting the complexity of potential bugs and problems.

Wednesday, May 15, 2013

Box for the outdoor unit

Bought a plastic box today at one of my local retailers and turned it into a custom case for my outdoor unit. This version isn't waterproof (a quick google search told me it would take some more in-depth engineering than I wanted to do for my first version), but it is a great proof-of-concept.



I cut holes in the plastic using a dremel tool. Most of the holes were in a removable side panel, making things easy, though the hold for the camera was in the box top. I learned a few lessons: when I routed the hole for the battery charging cable, I didn't think of how I would mount the circuit board and connector to the side-panel. In the end I found a piece of wood that was the right thickness to fit between the box and circuit, and used to 8-32 bolts to hold everything in place. Definitely will need a better solution for a water-proof model, as these are 2 unnecessary holes in the case. The rest of the build was quite straightforward, and took around 3 hours. After the break are some more photos and details.

Tuesday, May 14, 2013

Code Updates and a Time Lapse Video

Got my first time lapse video captured and online. Images were transmitted wirelessly using XBee radios from the battery-powered unit to the Arduino basestation. I copied the files to my computer, and converted them to jpg files using the converter in the code repository. Then, using Time Lapse Assembler, I made the 100 images into a 7 second movie at 15 FPS. The video is shown below:



Next steps will be on the hardware side:

  1. Making a waterproof case for the unit that properly secures all the wires
  2. Adding a potentiometer and LCD screen for some user controls and feedback over operation

Tuesday, April 23, 2013

Transmission errors fixed

Made a nifty change in my code allowing me to shorten delay times and eliminate transmission errors from propagating into the image. Now when a non-full frame is received, the code requests a repeat of that frame. Results seem good, while 10 ms delay does not work (probably not enough time for the signal to be sent and processed), 100 ms seems fine, and probably down to 80 or 70 ms could also work!

Fig. 1. Image taken at 100 ms delay time, which previously would have contained transmission errors (see previous blog posts).
Code is uploaded to the repository. This is much better than posting a new file each time!

Monday, April 22, 2013

Software Repository Up

The software repository is now up and available from Google code here and uses Mercurial. I'll be putting my files in here from now on, and try to do a better job to keep some naming consistency and documentation. That is all for today.

Sunday, April 21, 2013

Wireless photo transmission

Today is a pretty big milestone in my project. Actually over the last few days I've made a lot of good progress, so today's blog post will be a big one.

First the achievement:
I transmitted wirelessly from outdoors to inside. Still a lot of tweaking and streamlining to go, but the rough idea is there. Here is the photo:
Fig. 1. The camera took a photo outside, and transmitted it about 6 m to the Arduino indoors. The errors are probably due to missing bits or frames during transmission.

To get there, a bunch of work was necessary. To summarize:

  1. Modified my SD card photo storage program to communicate with the Lynxcamera over the UART instead of software serial. 
  2. Programmed my XBee transmitters to work at 38400 baud.
  3. Connected the Lynxcamera to the XBee and battery module, to capture photos remotely.
After the break I discuss the challenges with each of these separately, include some photos of the setup, and post my code.

Sunday, April 14, 2013

SD card adventures

This morning I went to NCIX and bought myself a microSD card. It was the ADATA 16 GB microsdhc class 10, and worked great with the Sparkfun microSD shield. The card came pre-formatted in FAT32. I found a copy of FAT libraries for the Arduino by William Greiman . After changing the CS pin in the software to be 8 (the software default was 4), the ReadWriteSdFat example code executed perfectly. I was also able to read the test file on my computer.


The next step was to collect a camera image, and store it on the microSD card. To do this, I adapted my previous LynxCamera code to make LynxCamera_SD. In this version of the software, the camera and SD card are both initialized. The user presses a keyboard button to tell the camera to take the photo. This time, instead of streaming the photo to the console, it is logged to the SD card. I can eject the SD card, insert it in my computer and use my conversion script to make it into the beautiful image of my apartment below.





While this works, I have observed a couple disappointments already. Getting the data from the camera onto the SD card is slow. I may be able to update the baud rate slightly, but at 38400 I was seeing transmission errors, so there is not a ton of speed to be gained here. The camera itself is a bit disappointing (though I was sort of expecting this). The photos have poor contrast, and are a bit dark. Seems the exposure time is automatically set, so I don't have a ton of flexibility here. Finally, I'm already at 15508 bytes out of a potential 30720... not leaving me a ton of room for doing LCD screen, radio and push button integration. 

But I think there is still lots of potential for this project! I'm charging my battery at the moment, so that, as the next step, I can start integrating the radios into this system. I think I will try to get all the aspects of this project integrated before starting to optimize the speed and space utilization.

Wednesday, April 10, 2013

Shift register working

Its a minor victory, but its been almost a month since I've had time to work on this project so I'll record it anyway :). Fixed a short to ground on one input pin of the shift register. The I used the Arduino shiftIn() function to read from each pin of the 74HC165. A simple sketch is available here. Hopefully soon I get the DIP switch soldered on, and can start using this as some input into the Arduino for testing and debugging.

Sunday, March 17, 2013

Battery-powered Radio unit

Connected my battery charge-booster and XBee radios together today for a proper radio test, and had some very good results. The XBee was on a regulated XBee Explorer, taking care of the 3.3V signal conversions and power conversion. I connected the power directly to the output of the charge-boost, and then did a loopback test with XCTU (see previous post). The result was great! Over 99.8 % success rate across the room. Couple photos of the setup below.

Fig 1. Battery powered wireless unit.
Fig 2. Computer connected XBee unit. The red board in the middle contains some electronics for my DIP switches (pullup resistors and a shift register).
Eventually the battery powered unit (Fig 1.) will have the camera connected to it, so that the photos will be sent wirelessly.

In Fig. 2, you can just see the other part of the project I have been working on: shift register for my mode switches. The SD card reader shield contains a mini-protoboard which I have been using to my advantage here to hold all my components (8 resistors and an IC). A 90 degree header sticks out on one end, which I will use to connect this shield to my switches. Looks like there is still some room remaining on the protoboard, which will be good for when I add in some other sensors. However I was having a strange result with one of my pull-up resistors, so I'll have to do more testing before I can say that part of the project is ready.

Saturday, March 16, 2013

First Linksprite Photos!

Connected my LinkSprite camera directly to my Arduino to investigate the photo quality and software. I was using the sample software from the Sparkfun product description page. The image streamed to the serial monitor, which I copied and pasted to TextEdit and saved as a .txt file (plaintext). I used the python script from an instructables Bird Feeder project to convert this to a usable jpg file. This I was able to open directly.

During my testing I made a number of observations. Running at 38400 baud between the camera and Arduino was creating some errors (Fig. 1), so I changed to 9600 baud which eliminated the errors (Fig. 2). I also played a bit with the delays in the sample code, and moved some functions around to (hopefully) improve the speed of data transfer. My modified code is available here. Connections to the LynxSprite camera are: +5 and gnd to respective pins on Arduino. TXD to Arduino 4 and RXD to Arduino 5.

Fig. 1. Some transmission errors cause image to appear improperly (due to jpg encoding). Transfer rate: 38400 baud

Fig. 2. No transmission errors noted at 9600 baud.
Next I will connect and get my radio's working (including my battery powered radio unit) and test out some wireless photo transmissions.

Monday, March 4, 2013

Radio Testing

I bought my XBee radios over 3 years ago, but never actually got them working. I've been playing around a bit with them in my lab, and happened to come across a document explaining that an Arduino with XBee shield running an empty sketch can play the role of an XBee Explorer so decided to try it out. I hooked up a loopback circuit on my reciever, and used the digi X-CTU software to run the test. Results were flawless! Had my XBees up and running in less than 10 minutes talking across a rather small gap... will do some proper range tests once I get the battery and stuff sorted out.

99% Success rate!!!
Test setup showing my not-quite overlapping-antennas
Interestingly it seems the antennas are not required for communication... the u.fl connector alone can support some degree of signal at least over the short range tested. (As a side note, I got the antennas from ebay for about $5 including shipping). But unless I run into mass restrictions, the antenna will stay for now... at worst I can always take off the plastic casing and keep the wire whip.

In other news, I'm getting ready to defend my thesis so I'm not planning on ordering parts anytime soon... but defence date is in 2 weeks so... more electronics in the near future? I think so!

Tuesday, February 12, 2013

Serial Time Lapse Camera - Project Schematic and BOM

For anyone who wants to follow along and make this project themselves, here is some stuff to get you started. First, my Sparkfun Wishlist. Next, some parts you will also need:

  • 1K and 10K resistors for pullup and transistor level-shifter
  • NPN transistor (2N2222 or similar)
  • Arduino (I am using Duemilanove)
  • Pair of XBee radios
I'm sure I've forgotten some stuff, but hopefully nothing major. Might be worth a double check on the schematic.

A system block diagram (Fig.  1) is shown to give an overall idea of the project. The wireless unit is battery powered, using a USB LiPo charger. The charger also boosts the voltage to 5V. This is used by the camera directly, and the XBee through the regulator, which also takes care of level shifting the Tx and Rx pins to communicate with the camera. While the camera datasheet says 3.3V operation is feasible, blog posts said otherwise, so I opted for 5V operation. 

In the base unit, an Arduino Duemilenove is the brains. XBee shield is stacked on a microSD shield (I believe these come together as one unit now, but my XBee shield is older). An LCD display is used as output to provide feedback to the user (eg. displaying the time between shots in the time lapse mode). DIP switches are used to set the mode time-lapse vs. high speed, what sensor to use, etc. and to save pins a shift register is used here. A push button and potentiometer will also be part of the UI (cycling through menus, or selecting time between shots).

Fig 1.  System block diagram of the serial cam project.
A lot of the parts are boards directly from Sparkfun, however some wiring will need to be done around the Arduino. I don't plan on making a PCB, instead I probably will put it onto some protoboard, but below is a schematic (Fig.  2) and link to eagle file for your perusal. It would be trivial to make a PCB I believe. Parts used are from the Sparkfun eagle libraries whenever possible. Most of the difficulty was in Arduino pin allocation, the connections themselves did not require much engineering.

Fig.  2. Schematic of the Base unit (Arduino etc.). 
Up next, mechanical design. I'll do up some drawings for my boxes, find a slick way to make the outdoor unit waterproof, and make sure all the parts will somehow fit nicely. Then there might be a short pause in the project, as buying parts before I finish my thesis sounds like a very bad idea...

Monday, February 11, 2013

Serial time lapse camera - Introduction and concept

Introduction:
This project started as a justification for owning XBee modules (which I have owned for 2 years but never properly used). But I think its a good stepping stone to an even bigger project: my future quadcopter. So here goes: the initial design of my time lapse camera that sends images serially.

The concept:
A small waterproof box outside my apartment holds a tiny camera, battery and radio. Inside my apartment, a radio attached to an Arduino gets the images and writes them to an SD card. The Arduino also contains an LCD, set of dip switches (to set the mode), multiple sensors (IR and PIR) for detecting motion and a potentiometer for controlling settings (likely the time between shots). Once my budget and skill-set expands, this same camera can be mounted onto a flying quadcopter, take photos from the sky, and send them back to Earth!

Whats next?
I'll be working on a BOM, schematic and mechanical design over the next couple weeks, and upload them as I complete them. So far I have managed to sort out how to use allocate of my Arduino pins (yes, a shift register was necessary). Got my schematics drawn on my lab notebook, so I'll do them in Eagle shortly. I do have some concerns about processing time of the Arduino and whether the MCU can handle interfacing to this many devices. I guess prioritizing may be necessary.

Stay tuned! Lots of fun to follow.

Tuesday, January 29, 2013

Macbook 2 NAS project

My girlfriend's old macbook is sitting around the apartment, so I thought it would make a great NAS (well a better NAS than paperweight anyway). It has a 500 GB HDD, 2 GB RAM and a 2.16 Core 2 Duo processor. My initial scheme was as follows:

1 - Get NAS4Free
2 - Make a bootable flash drive, and boot NAS4Free. Test and then use the Live USB to install NAS4Free to a second flash drive.
3 - Erase primary HDD on macbook, connect to router and use as a NAS
4 - (optional) Install an iTunes server on the flash and get that working too

After the break I'll outline the fun times that I went through on my quest for a MacBook NAS.


Sunday, January 13, 2013

Digital control of an SRF05

The SRF05 is an ultrasonic sensor (datasheet). Connecting it to an Arduino has been done and is a staightforward task, for example see this site: http://luckylarry.co.uk/arduino-projects/arduino-sonic-range-finder-with-srf05/. To beef up my digital logic skills a bit, and play around with some old ICs I had, I wanted to control the SRF05 using only digital logic, and display some sort of visual representation of its output with LEDs.

This task was first broken down into a simple state machine:
  1. Generate a 10 us pulse to turn on the sensor
  2. Clear a shift register (HC595, datasheet)
  3. Count the length of the output signal of the sensor and set shift register bits appropriately
  4. Latch the shift register output to light up LEDs
For a system block diagram, schematic and some results, check out the rest of this post after the break.