Friday, July 6, 2012

Adding a FTDI chip to a Raspberry Pi

Over the past month of owning my Pi, one lacking feature bothered me. I had worked with a beaglebone for a few months beforehand and had gotten used to the easy, single cable development system on the beaglebone, so I decided to give my Pi a FTDI connection over the included micro USB port. The concept was simple and despite being a pain to solder, was pretty simple to implement.


For this hack, we only need a few of the pins on the FT232RL. We need TXD, RXD, AGND, GND, VCC, VCCIO, 3V3OUT, and TEST. You can start out by shorting the TEST and AGND pins, and the VCC and RESET# pins. After this, run a small piece of wire from 3V3OUT to VCCIO, and a small piece of wire from the GND next to VCC to AGND/TEST. The VCCIO pin takes in the voltage supply for the RXD and TXD pins, and since the Pi is 3v3, we need to tie it to the 3V3OUT pin voltage source. A problem that took some reading to figure out is that TEST needs to be pulled to ground in order for the device to enumerate correctly, or else the device will connect, but quickly disconnect with error messages about improper IDs.

After you have done all the bridging and shorting, the hardest part begins, attaching the ~30AWG wire to the FTDI chip. If your up to making a incredibly discreet breakout board and have it fit on the Pi, you'll likely save yourself some time, but due to time and money constraints, this works. You need to connect wires to TXD, RXD, GND/AGND/TEST jumper, VCC, USBDM, and USBDP (USB plus and minus). The latter two are what we will be connecting directly to the onboard usb header.



The next step is attaching everything to the Pi. Once you have finished soldering everything and are sure that you want to continue, you can superglue or epoxy your FTDI chip right onto the Raspberry Pi. For this step, solder the VCC wire to TP1 and the GND wire to TP2 for ease, as we do not want to crowd the usb header. After that, attach the RXD wire to the TX pin on the pin header, and vice versa for TXD and RX. After all those, it's time to attach the USB wires to the header.

 As you can see in the photo and the schematic above, the second pin to the left is D-, so solder the USBDM wire, and to the center/third pin solder the USBDP pin. After all this you should now be able to attach your RasPi, type "screen /dev/ttyUSB0 115200" and see your boot commands. If you haven't set your Pi up to have a serial tty, it's time to set that up now.




In order to see boot messages over serial, your cmdline.txt should look similar to this:


And in your /etc/inittab file, change the line that should read similar to:
1:2345:respawn:/sbin/getty 38400 tty1
and change it to:
1:2345:respawn:/sbin/getty 115200 ttyAMA0

After that, you should be able to do single cable development on your Pi. Good Luck!

Links:
Raspberry Pi Schematics
FT232RL Datasheet



Saturday, June 30, 2012

Update

Hi. Thanks for all the success with my first post, I can't believe it actually made it to Hack a Day and Adafruit, you can imagine the shock I had when I was looking at my google reader and see a photo of my desk on it :D. Over the next week or two, I'll be doing a few more projects with my RasPi, hopefully adding a nice ftdi chip on board to make my life a bit easier and keep working on my PyLCD  project to make it as portable as possible. Of course, this all depends on how fast UPS wants to be. Thanks for all the comments and views.

Saturday, June 23, 2012

Running a HD44780 LCD over I2C (On the Raspberry Pi)

First Post! ... Now that that's over, I'm one of the lucky few/many people who has been able to get the Pi, so time to start spitting out libraries and tutorials. Today I'm going to start by focusing on getting a HD44780 lcd to work with the RasPi, since these are incredibly common, and some of the cheapest and easiest character lcds to work with.

One of the major problems plaguing the RasPi is the lack of GPIO, and the weird placement and random numbered GPIO pins broken out, making any code using them much more disorganized than if consecutive  GPIO pins had been used. In addition to the inconvinience of using the GPIO, the LCD uses 5v, while the RasPi is strict 3.3v. In order to prevent any chance of damage to my Pi, and to solve the problem, I opted to use a PCF8574 I2C 8 bit IO expander. This makes it easy enough to use the bottom four bits of the expander for LCD data, and the next 3 bits for RS, R/W, and EN. To control the LCD this way, I wrote up a nice library to get things working on the lcd.  In addition to this, I added a few extra bits to the library so that anyone can add more devices to it, and wrote a class for the tmp102 so we can have some live data to display.
The Raspberry Pi wired up to a serial bridge, PCF8574 Port Expander,
and a tmp102 12bit temperature sensor

eLinux has a guide on how to build and install the kernel, to get a updated kernel with the drivers use this git repository: https://github.com/bootc/linux
This library makes it very simple to use both these devices with the RasPi. Before using the library, you must load the i2c-dev module. At the time at which I started this project, the default Raspberry Pi linux tree was outdated and did not include spi and i2c userspace drivers.

After you get your new kernel installed, load the i2c-dev module, and place pylcd.py in whichever directory your working in, then we can move on to a simple sample program.




This is just a simple temperature display program using both the lcd and the tmp102. Despite being hard to see, the RasPi is connected through the i2c0 port with GPIO0 as SDA, and GPIO1 as SCL. Hopefully this library can help a few people get further with the RasPi and be part of some great projects. In the following weeks I plan on posting more content centered around the Raspberry Pi and other projects. If you use this in your project, please contact me, I would like to see how this libraries being put to use. Good Luck!




Links:

https://gist.github.com/2962884 The libraries somewhat regularly updated gist