Tag Archives: PIC

Driving OLED Displays

In a recent project I used a small 128×64 pixel OLED display module. These modules are great because the provide a clear and vivid display while requiring no back lighting. The display I used had a Systech SSD1306 controller fitted. The internet is rife with examples of code for driving these displays so I had it up and running with fairly minimal effort.

Having decided to use these displays on another project I am currently working on I found them on the R/C model site HobbyKing. Turns out the MultiWii flight controller (Arduino based flight controller originally using gyroscopes and accelerometers from the Wii controllers) uses an add-on OLED display module which no surprise features a 128×64 OLED display driven but the SSD1306 controller. As I was already ordering from Hobby King I decided to bundle one in with my order.

When the display arrived I assumed since both modules used the same display drivers the code I had already written would work out of the box. Wrong! Come on things are never that simple. Time to start investigating. First thing was to look at the two displays see how they compare. One thing that strikes you straight away is the lack of components on the new display (yellow PCB) compared with the old display (blue PCB).

Working_labelledWorking display module.
Not_Working_labelled

Not working display module.

Next step was to start reading the data sheet to see how this controller is configured. The pin out for the connections to the display can be seen below. I have also labelled them on the pictures above.

Pin Connection Description
1 N/C No connection. (GND)
2 C2P Charge pump capacitor.
3 C2N Charge pump capacitor.
4 C1P Charge pump capacitor.
5 C1N Charge pump capacitor.
6 VBAT DC/DC converter supply.
7 N/C No connection.
8 VSS Logic ground.
9 VDD Logic power supply.
10 BS0 Protocol select.
11 BS1 Protocol select.
12 BS2 Protocol select.
13 CS Chip select.
14 RESET Driver reset.
15 D/C Data/Command select. In I2C mode, this pin acts as SA0 for slave address selection.
16 R/W Read/Write.
17 E/RD Enable Read/Write.
18 D0 Input/output. When I2Cmode is selected, D0 is theserial clock input SCL.
19 D1 Input/output. When I2Cmode is selected, D2 & D1 should be tired together andserve as SDAout & SDAin.
20 D2 Input/output.
21 D3 Input/output.
22 D4 Input/output.
23 D5 Input/output.
24 D6 Input/output.
25 D7 Input/output.
26 IREF Brightness current reference.
27 VCOMH COM signal high voltage. A capacitor should be connected between this pin and VSS.
28 VCC OEL panel power supply. A stabilization capacitor should be connected between this pin and VSS when the converter is used.
29 VLSS Analog ground.
30 N/C No connection. (GND)

The controller has an internal charge pump regulator circuit for generating the 7.5V required by the display. Two external capacitors are required. These are connected between C1P/C1N and C2P/C2N and can be seen on both displays.

Both VCC and VCOMH have decoupling capacitors down to GND as outlined in the data sheet. The brightness current is set by the resistor between IREF and GND. The working display using 910K while the non working display opting to use 560K. The 3.3V regulator provides the required logic voltage.

Interestingly it turns out the controller supports communication over I2C, SPI (3 and 4 wire) and parallel. The protocol selection pins BS0-BS2 allow different protocols to be selected. Both displays have BS0 and BS2 are tied to GND while BS2 is tied to the positive supply which as expected sets the mode to I2C.

When configured for I2C mode D0 acts as the serial clock input. The data sheet stipulates that D1 and D2 should then be connected together to act as the serial data line. On closer inspection of both displays it becomes apparent this is the case the working display (blue PCB) but not with the non working display (yellow). Another thing the working display appears to have pull up resistors connected to SCL and SDA. Something you would expect with I2C comms. The non working display has no pull ups fitted.

Having said that the non working display appears to have three unpopulated foot prints on the PCB allowing for pull resistors to be fitted and for D1 and D2 to be connected together. So the first I did was to add and a zero ohm link between D1 and D2 joining them together. I didn’t bother with any pull up resistors. After fitting the display back into my development board and powering up to my surprise it worked!!

I can only assume when configured for I2C operation D1 acts as the serial input to the controller while D2 acts as the output. Joining the two must allow the acknowledge bit set by the controller to be read by the driver. The driver could have been modified to remove the need for the acknowledgement but this would have meant changing the code to be device specific which I didn’t want to do.

One nice feature on the old display is the ability to change the slave address. In I2C operation the Data/Command pin can be configured to set the lowest bit of the slave address SA0. Allowing the slave address to be either 0x78 or 0x7A. Meaning more than one display could fitted on the same bus.

Another slight gripe is the lack of power on reset circuitry on the new display. The working display has a simple reset circuit comprising R1, C1 and D9. The RC network ensures the reset pulse is present while the supply voltage rises keeping the controller in reset while the supply stabilises. D9 allows C1 to quickly discharge on power down in order to generate a reset pulse on power up in the case of short power downs or spikes. Having the reset pin tied directly to the supply, in the case of the new display, means the reset pin will rise of the same rate as the supply which is not ideal. The track could be cut and a reset circuit added but since it worked I wasn’t going to start modifying it.

 

OBD2 Adaptor Teardown

A number of years back a bought one of those cheap bluetooth OBD diagnostic tools from eBay. I cant remember why I bought it now (obviously for use on the car) but I must have only used it a couple of times. Having found in my desk drawer at work last week I decided to take it apart and have a look inside. From what I recall I only paid around £10 for it so was quite intrigued to see what you get for your money.

The device has “ELM327” written on the top of it. For those who don’t know the ELM327 is a programmed micro controller produced by ELM Electronics for translating messages from a vehicles on-board diagnostics (OBD) interface. According to Wikipedia the ELM327 is implemented on a PIC18F2480 micro controller from Microchip. Vehicles that support OBD communicate over one of a number of protocols. For older vehicles this tends to be either ISO 9141-2, ISO 14230-4 KWP or J1850 pulse width and variable pulse width modulation. Modern cars tend to use the controller area network (CAN) protocol. The ELM327 supports all of these protocols.

Further research reveals that ELM failed to implement any code protection on the original ELM327 chips. These chips were then cloned and form the basis for the majority of the cheap Chinese imports you now find on eBay. The version number in the firmware of these clones also appears to have been modified to report versions newer than the original release even though the functionality remains the same. Most of the adaptors currently on eBay claim to be v1.5. I have been unable to find any reference to a v1.5 on the ELM website.

OBD2 Device

Here is a picture of the PCB after it was removed from the case. The OBD connector which is connected via a 16 pin ribbon cable to the pin header has also been removed. The soldering looks good. All the components appear to be fitted correctly. We can see the main micro controller is indeed a PIC18F2480 the same processor ELM use for their ELM327. No labelling here so its more than likely the PIC18F2480 has been flashed with the ripped off firmware.

Now comparing this PCB with suggested example circuit diagram on the ELM327 datasheet. It quickly becomes clear this example has been adopted with some minor modifications. An off the shelf Bluetooth module (middle right) has been added. The RS232 level shifting has been removed since the TX & RX lines on the PIC connect straight through to pins on the Bluetooth module. I haven’t gone over the board component by component but you can clearly see in addition to the main micro controller, the MCP2551 CAN transceiver, the 78M05 5V regulator (bottom right) used in place of a 78L05 on the schematic. The 1.5A 50V rectifier diode in line with the battery voltage for reverse polarity protection. The LM317 adjustable regulator used to control the J1850 bus voltage. There appears to be additional filtering on the board as well.

ELM327 Datasheet

The bluetooth module looks like the e-Gizmo EGBT-046S. Versions on eBay appear to be known as the HC-05 or HC-06. The difference being the HC-05 can be configured as a master whereas the HC-06 cannot apparently. The main chip on these boards is a CSR BC417143 BlueCore® 4-External single-chip radio and baseband IC. Below it is the 8Mbit of external flash containing the firmware.

After applying power to the header and successfully pairing it with my PC I was able to communicate with it using puTTY. The ELM327 AT commands list contains a list of all of the commands supported by the device. Now obviously I couldn’t issue commands to poll vehicle information but I can send AT commands to perform simple tasks such as reset the device or report the firmware version number.

I reset the device by sending an “ATZ” command to which the device responded with “ELM327 v1.4”. Interesting. Sending the command “AT@1” returned “OBD2 to RS232 Interpreter”. This seems to be valid. However sending the command “AT@2”, which is only supported in firmware versions v1.2 and greater, should display the device identifier. The device returned no response. This indicates to me as expected that this device must be one of the cloned originals.

Still putting this into perspective. The original ELM327 chips from ELM Electronics are priced at $18 and that’s just for the IC. Add in the additional cost of the CAN transceiver, the extra components, the PCB and a case and you could not even build one yourself for less than what I paid for it. And besides it works!