Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
blog:car_stuff_pycosworth_hardware [2021/08/18 18:19] – [Prototyping & Testing OLED User Interface on a PC] johnblog:car_stuff_pycosworth_hardware [2021/08/18 19:05] (current) – [Making a Gauge Pod] john
Line 13: Line 13:
 //Note: None of the examples here are necessary if you only intend to use PyCosworth on a laptop using the basic USB to serial cable connected to your ECU.// //Note: None of the examples here are necessary if you only intend to use PyCosworth on a laptop using the basic USB to serial cable connected to your ECU.//
  
-===== Connecting an OLED Screen =====+===== Connecting an SPI-based OLED Screen ===== 
 + 
 +TBC 
 + 
 +===== Connecting an I2C-based OLED Screen =====
  
 You can use PyCosworth without any display functions, but.... it would be //pretty limited//. Here's how you connect up a relatively standard OLED display when using PyCosworth on a Raspberry Pi. You can use PyCosworth without any display functions, but.... it would be //pretty limited//. Here's how you connect up a relatively standard OLED display when using PyCosworth on a Raspberry Pi.
Line 198: Line 202:
 </code> </code>
  
 +//Note: if the power/ignition is restored before the countdown timer expires, the shutdown will be cancelled and PyCosworth will go back to normal operation. This is especially handy if you have your car in the garage for work, or for fault finding and are stopping and starting the engine regularly.//
 ==== Other Considerations ==== ==== Other Considerations ====
  
Line 235: Line 240:
  'luma_driver' : None,  'luma_driver' : None,
  'screen_refreshTime' : 0.02,  'screen_refreshTime' : 0.02,
- 'i2cPort' : 0, # Replace this with the I2C bus you are connecting to. This is the default for Pi pins #03 & #05 + 'i2cPort' : 0, # Replace this with the I2C bus you are connecting to. This is when using the normally 'hidden' I2C bus 0 on a Pi with pins #27 and #28
  'i2cAddress' : 0x3c, # Replace this with the device ID of your OLED module as returned by i2cdetect  'i2cAddress' : 0x3c, # Replace this with the device ID of your OLED module as returned by i2cdetect
  'mode' : [GFX_MODE_NUMERIC],  'mode' : [GFX_MODE_NUMERIC],
Line 296: Line 301:
  
 {{:blog:pycosworth:img20210818132836.jpg?400|}} {{:blog:pycosworth:img20210818132851.jpg?400|}} {{:blog:pycosworth:img20210818133548.jpg?400|}} {{:blog:pycosworth:img20210818132836.jpg?400|}} {{:blog:pycosworth:img20210818132851.jpg?400|}} {{:blog:pycosworth:img20210818133548.jpg?400|}}
 +
 +Painted and with buttons and screen fitted:
 +
 +{{:blog:pycosworth:img20210818182938.jpg?500|}} {{:blog:pycosworth:img20210818190355.jpg?500|}}
  
 === Connections === === Connections ===
Line 331: Line 340:
 ==== Software Configuration ==== ==== Software Configuration ====
  
 +First, you need to install the software needed to flash the i2c-tiny-usb firmware to the Digispark board. This uses the Arduino IDE and supporting toolset, which is documented for the Digispark board here: http://digistump.com/wiki/digispark/tutorials/connecting
 +
 +Ultimately, you only need the //micronucleus// tools installing, then download and flash the [[https://github.com/harbaum/I2C-Tiny-USB/blob/master/digispark/main.hex|firmware]] from the i2c-tiny-usb project. Once that is complete, plug the Digispark back into your PC and it should be detected as an I2C interface, and can be queried with **i2cdetect** just as the tools works on a Pi.
 +
 +On my Linux desktop, the Digispark board appears as I2C bus #08 when plugged in:
 +
 +<code>
 +i2cdetect 8
 +WARNING! This program can confuse your I2C bus, cause data loss and worse!
 +I will probe file /dev/i2c-8.
 +I will probe address range 0x03-0x77.
 +Continue? [Y/n] y
 +      1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
 +00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 +70: -- -- -- -- -- -- -- --
 +</code>
 +
 +If you plug your OLED module in to the Digisparks pin connectors, as detailed above, it should show up in the output of i2cdetect.
 +
 +Remember to change your PyCosworth //libs/settings.py// configuration to set the correct i2c bus and device number, just as you would do on a Pi:
 +
 +<code>
 +GFX_MASTER_WINDOW = {
 + 'windowName' : 'Master',
 + 'oledType' : 'sh1106', # Replace this with the model number of your OLED module
 + 'width' : GFX_MASTER_SIZE[0],
 + 'height' : GFX_MASTER_SIZE[1],
 + 'spiAddress' : 0,
 + 'value_refreshTime' : 0.05,
 + 'sdl_framebuffer' : None,
 + 'luma_framebuffer' : None,
 + 'luma_driver' : None,
 + 'screen_refreshTime' : 0.02,
 + 'i2cPort' : 8, # Replace this with the I2C bus you are connecting to. This is when I plug it into the Digispark on my desktop PC
 + 'i2cAddress' : 0x3c, # Replace this with the device ID of your OLED module as returned by i2cdetect
 + 'mode' : [GFX_MODE_NUMERIC],
 + 'currentModeIdx' : 0,
 + 'currentMode' : GFX_MODE_NUMERIC,
 + 'sensorIds' : ['AFR', 'AMAL', 'BAT', 'CO', 'ECT', 'IAT', 'IGNADV', 'INJDUR', 'MAP', 'RPM', 'TPS'],
 + 'currentSensorIdx' : 0,
 + 'screen_cycleTime' : 5,
 + 'value_refreshTime' : 0.1,
 + 'screen_refreshTime' : 0.05,
 +}
 +</code>
 +
 +That's it. All I2C comms (including the graphics routines used by Luma.oled and in turn by PyCosworth) will work unmodified and you can run your OLED display from your PC:
 +
 +{{:blog:pycosworth:img20210817161146.jpg?400|}}
 ===== My Current Setup ===== ===== My Current Setup =====
  
  • blog/car_stuff_pycosworth_hardware.1629307152.txt.gz
  • Last modified: 2021/08/18 18:19
  • by john