0

I would like to write a bash to light up an OLED screen with SSD1306 driver, I can use below code to send commands:

echo -ne $cmd > /dev/spidev0.0

however the SPI clock seems too fast for SSD1306, is there a way to slowdown the clock (to like 4Mhz) in the shell? thanks for any advice, I am using pi zero W.

Ingo
  • 42,961
  • 20
  • 87
  • 207

2 Answers2

2

Sorry it's not a complete answer, but my experience so far

  • using the Python3 spidev library,
    • I can open /dev/spidev0.0 or /dev/spidev0.1,
    • I can set the clock speed (noting that this is not a precise frequency, but something like nearest power of two)
    • I can write data, via Python or directly with echo foo > /dev/spidev0.$N
    • It comes out on BCM10, BCM11.
    • BCM7 or BCM8 are selected for each device, sounds like an active high.
    • I'm hearing it with a pair of headphones (not recommended!) because I have no better kit handy.
    • after calling the close() method on the SpiDev object, data is either not written to the port anymore with echo or it happens at a speed too fast to hear on headphones.
  • I would guess that some kind of IOCTL call on the device sets the speed, and you might find this in the source for the Python library or the .so it calls. Sorry I haven't looked for you.
  • None of this is what I wanted, because I soldered my connector expecting to use the SPI1 bus on BCM20,BCM21... a separate question.

I'm using a Pi Zero v1.3

mcast
  • 31
  • 4
2

Build (make; sudo make install) this ioctl tool. Then you should be able to issue IOCTL requests supported by the SPI driver:

SPI_IOC_RD_MAX_SPEED_HZ, SPI_IOC_WR_MAX_SPEED_HZ ... pass a pointer to a u32 which will return (RD) or assign (WR) the maximum SPI transfer speed, in Hz. The controller can't necessarily assign that specific clock speed.

If you happen to use more scripting languages than just BASH, there may be easier ways, e.g. in Perl:

require "sys/ioctl.ph";
ioctl(...);
Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147