Difference between revisions of "User Interface"
(20 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
[[File:RPi-UI.jpg|thumb|300px|alt=The RPi_UI PCB|The RPi_UI PCB]] |
[[File:RPi-UI.jpg|thumb|300px|alt=The RPi_UI PCB|The RPi_UI PCB]] |
||
This is the documentation page for the RPi_UI board. |
This is the documentation page for the RPi_UI board. That can be found in the [http://www.bitwizard.nl/shop/index.php?route=product/search&search=user%20interface BitWizard shop]. |
||
== Overview == |
|||
⚫ | |||
⚫ | |||
If you run your Pi on the standard raspian wheezy image ([http://www.raspberrypi.org/downloads download]) you will need to do modify some config files. |
|||
See [[bw_tool#Setting up I2C/SPI under Linux | Setting up I2C/SPI under Linux]] |
|||
'''1.'''<br /> |
|||
''/etc/modprobe.d/raspi-blacklist.conf'' <br /> |
|||
Comment the line ''blacklist i2c-bcm2708'' <br /> |
|||
<br /> |
|||
The file should look like this afterwards: <br /> |
|||
<nowiki> |
|||
blacklist spi-bcm2708 </nowiki><br /><nowiki> |
|||
#blacklist i2c-bcm2708 </nowiki><br /><nowiki> |
|||
</nowiki> |
|||
<br /> |
|||
'''2.''' <br /> |
|||
''/etc/modules'' <br /> |
|||
Add ''i2c-dev'' at the end. <br /> |
|||
<br /> |
|||
'''3.''' <br /> |
|||
Reboot the pi. You should be able to see the devices ''/dev/i2c-0'' and ''/dev/i2c-1'' <br /> |
|||
== Assembly instructions == |
|||
== Specifications == |
|||
=== Possible Configurations === |
|||
== External resources == |
== External resources == |
||
Line 45: | Line 22: | ||
The [[Bw_tool]] is meant to provide a basic commandline access to the bitwizard expansion boards |
The [[Bw_tool]] is meant to provide a basic commandline access to the bitwizard expansion boards |
||
=== Related projects === |
|||
== Pinout == |
== Pinout == |
||
Line 74: | Line 50: | ||
The only LED is a power indicator. |
The only LED is a power indicator. |
||
== |
== Jumper settings == |
||
There is one 2x2 pin jumper (JP1), which controls which SPI bus (actually which SPI chip-select line) is routed to the AVRs slave-select pin, and which is routed to the reset pin (to enable reprogramming of the AVR):<br> |
There is one 2x2 pin jumper (JP1), which controls which SPI bus (actually which SPI chip-select line) is routed to the AVRs slave-select pin, and which is routed to the reset pin (to enable reprogramming of the AVR):<br> |
||
Line 81: | Line 57: | ||
Bottom pads/pins connected: SPI0 connected to RESET |
Bottom pads/pins connected: SPI0 connected to RESET |
||
Top (near the LCD) pads/pins connected: SPI1 connected to Slave-Select |
Top (near the LCD) pads/pins connected: SPI1 connected to Slave-Select |
||
The recommended configuration is to have 1-3 connected. The pins 1 and 2 are marked on the PCB. So 1-3 means the jumper is closest to the board edge, running from the "1" to the "J" of "JP1". |
|||
People with the buttons/LCD on I2C can/should not install any jumpers here. |
|||
There is also one solder jumper, SJ1, which controls the supply voltage on the SPI, I2C, and UART connectors:<br> |
There is also one solder jumper, SJ1, which controls the supply voltage on the SPI, I2C, and UART connectors:<br> |
||
1-2: 5V (left)<br> |
1-2: 5V (left)<br> |
||
2-3: 3V3 (right, near the PCB edge) |
2-3: 3V3 (right, near the PCB edge) |
||
We deliver this jumper in the "5V" position with a small PCB trace. If you want to switch to 3.3V you'll have to cut the small trace with a knife. |
|||
== Protocol == |
== Protocol == |
||
Line 90: | Line 72: | ||
To make the RPI_UI PCB do things, you need to send things over the SPI or I2C bus to the PCB. A comparison of the two protocols can be found [[SPI_versus_I2C_protocols|here]]. |
To make the RPI_UI PCB do things, you need to send things over the SPI or I2C bus to the PCB. A comparison of the two protocols can be found [[SPI_versus_I2C_protocols|here]]. |
||
The general overview of the SPI protocol is [[General_SPI_protocol|here]]. |
The general overview of the SPI protocol is [[General_SPI_protocol|here]]. |
||
the list of the default addresses is [[Default_addresses|here]]. |
|||
== The software == |
== The software == |
||
Line 96: | Line 80: | ||
Controlling the display works the same way as our SPI_LCD or I2C_LCD modules. Reading the pushbuttons is very much like the DIO module. The read and write ports are described below. |
Controlling the display works the same way as our SPI_LCD or I2C_LCD modules. Reading the pushbuttons is very much like the DIO module. The read and write ports are described below. |
||
=== |
=== Write ports === |
||
Some ports just set a single value. So writing more than one byte to such a port is redundant. Other ports are logically a stream of bytes. So writing more than one byte is encouraged. |
Some ports just set a single value. So writing more than one byte to such a port is redundant. Other ports are logically a stream of bytes. So writing more than one byte is encouraged. |
||
Line 124: | Line 108: | ||
| 0x13 || set backlight. |
| 0x13 || set backlight. |
||
|- |
|- |
||
| 0x14 || reinit LCD. The initialzation procedure of the LCD takes a long time. A timed delay of about 500ms is in order after issuing this command |
|||
| 0x14 || reinit LCD. |
|||
|- |
|- |
||
| 0x15 || send 0 to set overrun-status back to zero. |
| 0x15 || send 0 to set overrun-status back to zero. |
||
Line 150: | Line 134: | ||
|} |
|} |
||
=== |
=== Read ports === |
||
The rpi_ui board supports several read ports: |
The rpi_ui board supports several read ports: |
||
Line 164: | Line 148: | ||
| 0x13 || backlight intensity |
| 0x13 || backlight intensity |
||
|- |
|- |
||
| 0x15 || read FIFO overrun status. If different from previous value, you've had an overrun. Best to |
| 0x15 || read FIFO(first in, first out) overrun status. If different from previous value, you've had an overrun. Best to |
||
clear the screen and resend any data you want displayed. |
clear the screen and resend any data you want displayed. |
||
|- |
|- |
||
Line 245: | Line 229: | ||
== Using the RTC == |
== Using the RTC == |
||
We first designed the User Interface to be equipped with either an SPI RTC or an I2C RTC. In practice the driver for the i2c version was a lot easier, so we're not selling the ones with the SPI RTC unless you really, really want (and we haven't run out of boards by then). |
|||
The User Interface can be equipped with either an SPI RTC or an I2C RTC. |
|||
=== I2C === |
=== I2C === |
||
Line 252: | Line 235: | ||
The I2C RTC has a Linux driver, which is available in the standard kernels delivered with raspian. (and probably others too). |
The I2C RTC has a Linux driver, which is available in the standard kernels delivered with raspian. (and probably others too). |
||
Just |
Just use: |
||
modprobe i2c:mcp7941x |
modprobe i2c:mcp7941x |
||
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device |
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device |
||
Line 262: | Line 245: | ||
=== SPI === |
=== SPI === |
||
We are not aware of a device driver for the SPI version of the RTC. We can read/write the RTC with bw_tool from the |
We are not aware of a device driver for the SPI version of the RTC. We can read/write the RTC with bw_tool from the command line using the raw SPI bytes command line option "--hex". The CPU on the board has to enable the CS line for the SPI RTC. This limits the speed of the SPI transactions a bit (50 kHz has been verified working). |
||
bw_tool -s 50000 --hex 96 12 20 1 2 34 5 6 7 89 |
bw_tool -s 50000 --hex 96 12 20 1 2 34 5 6 7 89 |
||
Line 274: | Line 257: | ||
Refer to the datasheet of the MCP79522 for information on the registers of the chip http://ww1.microchip.com/downloads/en/DeviceDoc/22300A.pdf |
Refer to the datasheet of the MCP79522 for information on the registers of the chip http://ww1.microchip.com/downloads/en/DeviceDoc/22300A.pdf |
||
= |
= Examples = |
||
== |
== Read identification == |
||
read the identification string of the board. |
read the identification string of the board. |
||
Line 317: | Line 300: | ||
|} |
|} |
||
== |
== Set cursor position == |
||
move to line 1, character 5: |
move to line 1, character 5: |
||
{| border=1 |
{| border=1 |
||
Line 329: | Line 312: | ||
|} |
|} |
||
== |
== Bash script to show system informations == |
||
This bash script shows the current time and load averages of the cpu. The refresh is set to 5 seconds. |
This bash script shows the current time and load averages of the cpu. The refresh is set to 5 seconds. |
||
#!/bin/bash |
#!/bin/bash |
||
# What display to use: |
|||
DISPL="bw_tool -I -D /dev/i2c-1 -a 94" |
|||
# e.g. for SPI use: |
|||
#DISPL="bw_tool -D /dev/spidev1.0 -a 94" |
|||
#clean the display |
#clean the display |
||
$DISPL -W 10:0:b |
|||
bw_tool -I -a 94 -r 16 -v 0 |
|||
while true; do |
while true; do |
||
#get cpu loads |
#get cpu loads |
||
load=` |
load=`cut -d' ' -f-3 /proc/loadavg` |
||
#print the current time |
#print the current time |
||
$DISPL -W 11:00:b |
|||
$DISPL -t `date +%H:%M:%S` |
|||
#print the load averages |
#print the load averages |
||
$DISPL -W 11:20:b |
|||
$DISPL -t $load |
|||
#idle for 5 seconds |
#idle for 5 seconds |
||
sleep 5 |
sleep 5 |
||
done |
done |
||
== Default operation == |
|||
== Future hardware enhancements == |
|||
== Future software enhancements == |
|||
== Changelog == |
== Changelog == |
Latest revision as of 16:02, 14 January 2016
This is the documentation page for the RPi_UI board. That can be found in the BitWizard shop.
Installation
See Setting up I2C/SPI under Linux
External resources
Datasheets
Additional software
The Bw_tool is meant to provide a basic commandline access to the bitwizard expansion boards
Pinout
The 26 pin gpio connector is described at elinux
The SPI connector has the same pinout as the atmel 6-pin ICSP connector and is documented here: SPI_connector_pinout.
The I2C connector is documented here: I2C_connector_pinout.
The UART connector is documented here: uart connector pinout.
The analog connector has the following pinout:
pin | function |
---|---|
1 | 5V |
2 | Analog in |
3 | GND |
Some people report they find it difficult to read the names of the connectors on the PCB. We'll fix that in a future version. In the meanwhile:
Note that for the 20x4 version of the board, the connectors are in the same order with the same pinout.
LEDs
The only LED is a power indicator.
Jumper settings
There is one 2x2 pin jumper (JP1), which controls which SPI bus (actually which SPI chip-select line) is routed to the AVRs slave-select pin, and which is routed to the reset pin (to enable reprogramming of the AVR):
Left pads/pins connected: SPI0 connected to Slave-Select
Right pads/pins connected: SPI1 connected to RESET
Bottom pads/pins connected: SPI0 connected to RESET
Top (near the LCD) pads/pins connected: SPI1 connected to Slave-Select
The recommended configuration is to have 1-3 connected. The pins 1 and 2 are marked on the PCB. So 1-3 means the jumper is closest to the board edge, running from the "1" to the "J" of "JP1".
People with the buttons/LCD on I2C can/should not install any jumpers here.
There is also one solder jumper, SJ1, which controls the supply voltage on the SPI, I2C, and UART connectors:
1-2: 5V (left)
2-3: 3V3 (right, near the PCB edge)
We deliver this jumper in the "5V" position with a small PCB trace. If you want to switch to 3.3V you'll have to cut the small trace with a knife.
Protocol
To make the RPI_UI PCB do things, you need to send things over the SPI or I2C bus to the PCB. A comparison of the two protocols can be found here.
The general overview of the SPI protocol is here.
the list of the default addresses is here.
The software
Controlling the display works the same way as our SPI_LCD or I2C_LCD modules. Reading the pushbuttons is very much like the DIO module. The read and write ports are described below.
Write ports
Some ports just set a single value. So writing more than one byte to such a port is redundant. Other ports are logically a stream of bytes. So writing more than one byte is encouraged.
The rpi_ui board defines several ports.
port | function |
---|---|
0x00 | display data. |
0x01 | write data as command to LCD. |
0x08 | Set startup message line 1. After setting the startup message please wait 100ms before sending the next line. works from version 1.6+ |
0x09 | Set startup message line 2. |
0x0a | Set startup message line 3. |
0x0b | Set startup message line 4. |
0x10 | any data clears the screen. |
0x11 | move the cursor to line l, position p. l is the top 3 bits p is the bottom 5 bits of the data. |
0x12 | set contrast. |
0x13 | set backlight. |
0x14 | reinit LCD. The initialzation procedure of the LCD takes a long time. A timed delay of about 500ms is in order after issuing this command |
0x15 | send 0 to set overrun-status back to zero. |
0x17 | Set the boot-time backlight intensity. (0xff means: use programmed default (0xc0)) |
0x20 | set display number-of-lines. These are passed on to the display software, but seem to have little effect. |
0x21 | set display number-of-characters. |
0x70 .. 0x71 | Select which i/o is coupled to which ADC channel |
0x80 | Set number of ADC channels to read |
0x81 | Set number of samples to add (we suggest using a power of 2) (two bytes) See: annoying bug |
0x82 | Set ammounts of bits to shift accumulated sample value |
0xf0 | change address. But need to unlock first. See below. Might require a reboot to take effect. |
0xf1 | change address: unlock phase 1: write 0x55 here to start unlocking. |
0xf2 | change address: unlock phase 2: write 0xaa here to allow changing of the address (after writing 0x55 to f1). |
Read ports
The rpi_ui board supports several read ports:
port | function |
---|---|
0x01 | identification string. (terminated with 0). |
0x02 | read eeprom (serial number). |
0x12 | contrast |
0x13 | backlight intensity |
0x15 | read FIFO(first in, first out) overrun status. If different from previous value, you've had an overrun. Best to
clear the screen and resend any data you want displayed. |
0x16 | read FIFO bytes-in-buffer. The fifo is 32 bytes, So you can send 20 chars to display if the value is less than 12. |
0x17 | read stored backlight intensity. |
0x20 | read button 1 (1 means NOT pushed, 0 means pushed) |
0x21 | read button 2 (1 means NOT pushed, 0 means pushed) |
0x22 | read button 3 (1 means NOT pushed, 0 means pushed) |
0x23 | read button 4 (1 means NOT pushed, 0 means pushed) |
0x24 | read button 5 (1 means NOT pushed, 0 means pushed) |
0x25 | read button 6 (1 means NOT pushed, 0 means pushed) |
0x30 | reports which buttons have been pushed since last read of this register If you keep a button pushed, it will read out as 1 multiple times |
0x31 | reports which buttons have been pushed since last read of this register (V1.2 and up) If you keep a button pushed, it will read out as 1 only once |
0x40 | read button 1 (1 means pushed, 0 means NOT pushed) (V1.1 and up) |
0x41 | read button 2 (1 means pushed, 0 means NOT pushed) (V1.1 and up) |
0x42 | read button 3 (1 means pushed, 0 means NOT pushed) (V1.1 and up) |
0x43 | read button 4 (1 means pushed, 0 means NOT pushed) (V1.1 and up) |
0x44 | read button 5 (1 means pushed, 0 means NOT pushed) (V1.1 and up) |
0x45 | read button 6 (1 means pushed, 0 means NOT pushed) (V1.1 and up) |
0x60.. 0x61 | Return analog value (2 bytes) |
0x68 .. 0x69 | Return added and bitshifted analog value (2 bytes) |
0x70 .. 0x71 | Return which i/o is coupled to which ADC channel |
0x80 | Return number of ADC channels to read |
0x81 | Return number of samples to add (two bytes) |
0x82 | Return ammounts of bits to shift accumulated sample value |
Using the analog inputs
Please see this chapter on the page explaining the DIO protocol. There are two major differences:
- The internal reference voltage needs to be configured in a different way
- The mapping of the analog inputs; please use the following table instead:
IO pin | value |
---|---|
temp | 0xC7 (Vref=1V1) OR 0x47 (Vref=Vcc=~5V) |
ext | 0xC6 (Vref=1V1) OR 0x46 (Vref=Vcc=~5V) |
Example
Setup the ADC (only needed once after reboot):
bw_tool -a 94 -w 70:c7 //Set ADC channel 0 to temperature sensor, and internal 1V1 reference bw_tool -a 94 -w 80:01 //Set number of channels to sample to 1
Read the value:
bw_tool -a 94 -R 60:s // Read the result, output in hex
Using the temperature sensor
The temperature sensor is a MCP9700. It's output voltage depends on the temperature. For more information, please see the MCP9700 datasheet.
An initialization and readout script are available on the Temperature sensor example page.
Using the RTC
We first designed the User Interface to be equipped with either an SPI RTC or an I2C RTC. In practice the driver for the i2c version was a lot easier, so we're not selling the ones with the SPI RTC unless you really, really want (and we haven't run out of boards by then).
I2C
The I2C RTC has a Linux driver, which is available in the standard kernels delivered with raspian. (and probably others too).
Just use:
modprobe i2c:mcp7941x echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
and the module is loaded and detects the RTC.
You can then set the RTC with: "hwclock -w". This will write the unix clock to the RTC. Put a "hwclock -s" somewhere in your startup scripts to initialize the unix clock from the RTC. The version 1 raspberry pi's had the i2c-0 bus on the gpio connector, you for the older raspberry pi you'll need to change i2c-1 into i2c-0..
SPI
We are not aware of a device driver for the SPI version of the RTC. We can read/write the RTC with bw_tool from the command line using the raw SPI bytes command line option "--hex". The CPU on the board has to enable the CS line for the SPI RTC. This limits the speed of the SPI transactions a bit (50 kHz has been verified working).
bw_tool -s 50000 --hex 96 12 20 1 2 34 5 6 7 89
will write (0x12) the test-bytes 1 2 34 5 6 7 89 to the RAM at location 0x20 in the RAM.
bw_tool -s 50000 --hex 96 13 20 0 0 0 0 0 0 0 0
will read them back.
Refer to the datasheet of the MCP79522 for information on the registers of the chip http://ww1.microchip.com/downloads/en/DeviceDoc/22300A.pdf
Examples
Read identification
read the identification string of the board.
data sent | data recieved | explanation |
---|---|---|
0x95 | xx | select destination with address 0x94 for READ. |
0x01 | xx | identify |
xx | 0x73 | 's' |
xx | 0x70 | 'p' |
xx | 0x69 | 'i' |
xx | ... | etc. |
Send text to display
Display the string "Hello World!" (only the first 5 bytes of the string shown).
data sent | data recieved | explanation |
---|---|---|
0x94 | xx | select destination with address 0x94 for WRITE |
0x00 | xx | datastream |
0x48 | xx | 'H' |
0x65 | xx | 'e' |
0x6c | xx | 'l' |
0x6c | xx | 'l' |
0x6f | xx | 'o' |
xx | ... | etc. |
Set cursor position
move to line 1, character 5:
data sent | data recieved | explanation |
---|---|---|
0x94 | xx | select destination with address 0x94 for WRITE |
0x11 | xx | port 0x11 = set cursor position. |
0x25 | xx | 0x25 = 001 00101 = line 1 position 5. |
Bash script to show system informations
This bash script shows the current time and load averages of the cpu. The refresh is set to 5 seconds.
#!/bin/bash # What display to use: DISPL="bw_tool -I -D /dev/i2c-1 -a 94" # e.g. for SPI use: #DISPL="bw_tool -D /dev/spidev1.0 -a 94" #clean the display $DISPL -W 10:0:b while true; do #get cpu loads load=`cut -d' ' -f-3 /proc/loadavg` #print the current time $DISPL -W 11:00:b $DISPL -t `date +%H:%M:%S` #print the load averages $DISPL -W 11:20:b $DISPL -t $load #idle for 5 seconds sleep 5 done
Changelog
1.0
- Initial public release