Fighting with computers

Computers are not always friendly.

Thursday, March 29, 2012

The not so intuitive use of an IMU

A recent project required acceleration measurements to study a person's gait. I thought this could be done easily with one of the many MEMS (MicroElectroMechanical Systems) devices available in the market under the name of IMU (Intertial Measurement Units) or just accelerometers.

I settled with the cheapest acceloremeter I found on eBay with an I2C interface to connect it to a Funnel IO powered by a rechargeable Lithium battery. Funnel IO (or FIO in short) is an Arduino-like board that includes a USB-powered battery charger plus an XBee module interface on board. It can be programmed wirelessly but this proved to be a real PITA to get it working (and even after that, it does not work reliably).

Once I got some code grabbed from Arduino forums to read my sensor (MMA7660FC from Freescale) I was a bit shocked with the results. My sensor was a 3-axis accelerometer and  I was expecting a measurement of X=Y=Z=0 on my first test with the sensor static. I was wrong. I should have read first this wikipedia article.

It turns out that accelerometers use a "free-fall" reference frame. Bottom line is that the impact of the Earth gravity is taken into account. So even if the sensor is stationary some axis will be sensing the effect of the gravity and this will cause non-zero measurements. The sensor measures the forces a small mass inside experiences and gravity acts upon it even if there is no sensor motion.

Once I did understood my sensor was acting as expected and it was not damaged things progressed smoothly.

Sunday, March 18, 2012

Wireless 3D printing

Last week I had a "USB cable incident" with my Prusa (computer and printers are on different tables in my office). It was entirely my fault as I walked across the USB cable and I almost threw my printer to the floor. As a result, the ferrite torus I put in the USB cable to prevent EMI problems broke. Without it, I know prints may interrupt anytime due to interference.

While on eBay looking for a replacement, I realized that a Bluetooth module was costing less than $15 now. So I thought I could give it a chance to the idea of operating my printers wirelessly.   Later, I learned of an even cheaper module at $6.60, but this one is 3.3v only (which is ok if you are using this voltage for your Arduino, but I am using 5v).

A quick look at Sprinter firmware and Arduino Mega and RAMPS board specs revealed that Serial2 port using 16 (TX) and 17 (RX) pins was easily available on the ext4 connector of RAMPS board. And so was GND and +5V. Making it very easy to connect the Bluetooth module.



And for the firmware changes, I do have an easy solution if you can give up the usage of the USB serial communication for printing (which I was). Just do a search and substitution of string "Serial." by "Serial2." in Sprinter.pde (same idea could be applied to other firmwares) and that is all. This way your printer will no longer be usable from the USB but you can always go back by reloading the former version of firmware. Please note that if you enable SD printing you may need to do the string replacement in some other source files too (same simple replacement).


You need to configure the module to use 115200bps (or change the firmware to 9600bps which is the default module speed) and you can do that by selecting the AT mode and using serial interface (3.3 volts only!) you use AT+UART=115200,0,0 command. Please note this module uses 38400 bps when in AT mode. For this job I used Spakfun's FTDI basic breakout module.

Once configured, the module can be wired to the RAMPS board with four wires (GND, +5V, RX, TX).  Select the board in your favorite software (I use Pronterface) and you can connect and interact with your printer.

Problems ahead

Unfortunately, not all was a success (yet). For some weird reason, still to be determined (defective Bluetooth module, bad module firmware, ...), my happiness is not complete as there is a problem. Once I start printing, the print job is interrupted after a few moves.

The cause of the problem is that my Bluetooth module misses some characters in the RX line if Mega is not transmitting a character for more than ten seconds. The end result is that "ok" responses are damaged or lost entirely whenever the motion takes longer than ten seconds, so printing of large objects becomes a problem. But Bluetooth connection is never lost, so I guess the cause it is a poor implementation of power management in the Bluetooth module.

I hope that by replacing the module firmware or by adjusting some parameter I will be able to fix the problem. If not, I will be forced to buy a different module and keep this one for another task where this behavior won't be a problem.

Update: Once I replaced the Bluetooth module behaving badly from another [cheaper] supplier I have got it all working nicely and wirelessly at last.  It works in Linux, Windows and OSX.

Tuesday, March 13, 2012

Arduino RFID

This time I am interested on a particular application of this technology: My university has moved to RFID picture IDs for students and I was curious about how difficult it was to read the cards from an Arduino board. Our system is using 13.56 MHz cards, so I ventured into eBay territory. Almost anyone can type "Arduino RFID" there to get plenty of cards that allow you to read (and write) RFID tags/cards.

For those of you living in a cave, RFID is a wireless technology that allows you to both power and interact wirelessly with a card or tag that contains a digital unique identifier that optionally may include some rewritable memory too. Tags or cards themselves do not have nor need a battery but they contain a microchip and a coil to gather energy from nearby readers. That means that the card and the reader need to be pretty close for this to work (that is why the technology is dubbed as NFC or Near Field Communication).

After buying one card and waiting the usual two weeks for things to travel from China to my home using regular mail, I have tested the card with the sample software and I am pleasantly surprised on how simple this is: Reading and Writing works outside the box, though I have some problems with source code commented in perfect Chinese (a language I cannot read). Some understanding of Mifare cards is needed if you want to use the cards memory storage, as there are some security mechanisms you need to understand.