donderdag 20 november 2008

Microcontroller LCD interface using HD44780

This is doubtless the most simple way of hooking up a character based LCD display with a built-in HD44780 controller (and almost all character LCD displays are like this). The Vcc and Vdd are connected as usual, with the 0.1uF decoupling capacitor. For the contrast voltage a 10k potentiometer is used. Normally this has to be calibrated once, so a tiny one that you set with a screwdriver is good. The R/W is grounded, ensuring that the connection is write only (do NOT use a resistor for this. Quite some current goes through this pin, and not grounding it will cause the I/O ports to occasionally go into read mode, which will destroy your microcontroller, even if it is a PIC). The RS and E(nable) lines are hooked up to arbitrary pins on the 16F628A, and the D0-D3 are left disconnected. D4-D7 are connected to half a port of the microcontroller, in this case PORTA (RA0-RA3). Pins 15 and 16 are sometimes absent and are used to control the backlight. Regardless, they are left disconnected too.

Controlling this uses the 4-bit interface with maximum delays (it is not possible to use shorter delays, as it is a write only connection and there is no way of knowing whether the sent nybble has arrived). The software should show how it works. The initialization sequence is crucial, and I recommend copying it from the code, as it is easy to get wrong. When you see no characters appear, also fiddle with the contrast setting, as this could be set such that nothing displays.

woensdag 19 november 2008

Camera GPS official version

The final version of the camera GPS had to be smaller. In fact, a number of things needed to happen: smaller, lighter, own GPS module, PC connection and an LCD display. The picture shows the final version. Still slightly bigger and heavier than a flash module, with a rather clumsy 9V battery (which should clearly be replaced with a LiIon one) and a serial output port (which should become a USB port, which can also charge the LiIon battery). On the picture you can see the GPS module (the square at the top left) the LCD display (2x8 characters, on the right), the battery, the 6-pin ICSP connector, a white button, an on/off switch (at the bottom) and an RS-232 output (at the top). The system still uses the PIC16F628A and the 24LC512 memory. The circuit seems a bit awkward because of the attached flash port at the bottom. I did not yet make an enclosure for it.

On the picture you can see the GPS in operation. The display shows the number of the last picture taken (40) as well as the direction in degrees, the quadrant that we are in (NW) and the movement speed. Another picture, below, shows the actual coordinates, although the display is too small to show the smallest values: this is something that still needs to be addressed in the new version of the GPS software.

dinsdag 18 november 2008

7 segment displays

Seven segment displays are basically 8 LED in a pattern. The most convenient way of connecting would be to hook up each LED to one pin of a port, but usually this is not possible because ports have different uses and there is always a certain port you wish to use for a certain purpose. In this case the RX/TX pins in PORT B are used for the serial input, and RA4 is used for the I2C communication. This means we have to select other pins. This design avoids fancy PWM output to the LED and just allows them to be on and off. To avoid the LED dying from current drain I added 330 Ohm resistors. For a brighter result one can go as low as 220 Ohm, to save power you can go as high as 1k Ohm. The part of the software for controlling the LED display is very simple in this case: it just consists of subroutines that send the appropriate output to the port. Normally one would not do it this way, as this is inefficient. A lookup table would be better. In this case, however, there are a limited number of values, and it was meant as a prototype anyway.

Note that it might seem attractive to use a single resistor on the ground pin of the LED display. This, however, will cause the brightness to fluctuate and can even cause damage to the display, and is therefore not recommended.

maandag 17 november 2008

I2C EEPROM microcontroller connection

Hooking up an I2C device, like an EEPROM, is relatively simple. I2C uses a 2-pin bus, with labels SCL (clock) and SDA (data). In case your microcontroller has a built in I2C controller, it is wise to hook these two lines to that port. However, I generally write it in software, because the hardware is slightly more complicated than needed (it handles clock skewing, master/slave configurations and multiple devices) in this case. It also does not give you the nice three byte buffer, which the UART (serial port input) does. If you do write it in software, it is best to hook the data input to the so-called "open collector" port. On most older PIC microcontrollers, like the 16F628(A), this is RA4 (port A bit 4). Note that both lines need pull up resistors. The values of these resistors depend on the speed that you wish to transmit data over. The disadvantage of low values is the current drain on the system. 1k Ohm works well. Note that the 24LCxxx (xxx indicates the memory in bits, a 512 module therefore has 64K of memory) needs its own decoupling capacitor, which as usual I chose to be 0.1uF. The write protect line and the address lines can all be grounded, unless you plan to have more than 64K of memory: you will need to configure different addresses for each of the EEPROM in that case.

Reading the EEPROM runs at 400 kHz. Not very fast, but suitable (and it seems most of them allow you to go up to 700 kHz, if needed). Writing is slower: you can send up to 256 bytes to the EEPROM without any delay, but after that a wait is needed (so-called ack-polling) until the EEPROM is available again for other operations.

zondag 16 november 2008

Serial port for input


To allow a microcontroller to read from a serial port (but not write to it) is relatively simple. In principle it is a matter of hooking up a 10 kOhm resistor from the output of the serial cable to any pin of the microcontroller, at which point the microcontroller can read the incoming data using software (note that this could push the microcontroller outside of its specification, as you're using the protection diodes for another purpose). Usually, however, one does not want to rely on software to do the reading, as this is slow, time consuming and prone to errors. Most PIC microcontrollers, including the PIC16F628A, have a so-called UART, which handles the reading and writing of serial ports. Unfortunately you can not use the resistor trick in this case, as the signal is inverted and the UART can not handle an inverted serial signal. Fortunately a simple RTL circuit can solve two issues: the illegal use of the protection diodes inside the microcontroller and inverting the signal so it can be properly read, and this with only one additional transistor and resistor.

The provided circuit can handle almost any serial port, even if the voltage is out of specification. It assumes a male connector, for a female connector it needs to connect to pin 3 (as this is a read operation there is no problem if you make a mistake). Note that transistors are much slower at inverting than regular inverters, and that you should therefore not use very high baud rates.

zaterdag 15 november 2008

Camera GPS

Another project I work(ed) on was the camera GPS. The idea is that when you take a picture, your camera tends to send a signal to the flash port, which could trigger the flash if necessary. A very simple flash port just has an on/off switch, which could be hooked up to a GPS to record the current date, time and place so that you can later associate the picture with this information. The board shown here actually used to be a prototype for the servo controller featured elsewhere in this blog, but was modified to communicate with a gps. On the board you can see a 7-segment LED display in green, an on/off LED, a 24LC512 external EEPROM to store the results, a PIC16F628A microcontroller, an RS-232 input port that would hook up to the GPS, the usual 6-pin ICSP and a 74HC125, which seems useless but was used to hook up a smaller GPS module that worked on 3V. There is also the obvious 7805 power supply with 9V clip. This, as well as the software for the GPS camera controller, will all be explained in more detail in later posts, first another picture of the prototype hooked up to a camera (a Minolta X700 in this case, which worked really well).

Servo controller in action

Here is a short video that shows the servo controller working. As my 9V NiCd battery was still charging I used a regular alkaline one, which actually was better for the video as it made the servo motor respond slower due to the lower maximum current.