• SPI slave device help

    MicroPython spi
    5
    0 Votes
    5 Posts
    101 Views
    J
    @DualMatic since the chip using 16-bit words you should provide a 2-byte buffer for the data being read.
  • SPI + MS5540C driver

    Discussion spi sensor ms5540c
    2
    0 Votes
    2 Posts
    355 Views
    T
    hello there, Did you manage to solve this issue? :) Thanks
  • Display SSD1306 with lopy4 doesn't work

    LoPy ssd1306 oled spi
    5
    1
    0 Votes
    5 Posts
    624 Views
    G
    @paul-thornton no error display on the console and the display does not show anything. I give up with this module.
  • WiPy 3.0 and MPU9250, SPI interface

    WiPy 2&3 wipy 3.0 spi mpu9250 expansion board
    14
    0 Votes
    14 Posts
    1k Views
    P
    @alvaroav Hey glad its working. I've raised it in the team so hopefully the fixes will get ported into the next pybytes firmware release.
  • LOPY SPI Mikroe click module

    LoPy lopy spi sensor
    4
    0 Votes
    4 Posts
    506 Views
    robert-hhR
    @johncaipa said in LOPY SPI Mikroe click module: adc = (((buf[0] << 8) | buf[1]) & 0xfff) >>1 That one is wrong. You have to shift the raw value befor masking. The lowest bit of the returned value will not be at bit0 of adc, so you have to shift to to the right. Reason: The adc starts shifting out values at the 2nd (or third?) clock cycle, and SPI will create 16 clock cycles. So there are like 14 bits in the result buffer, of which only the high order 12 bits are valid. The others have to be discarded and the value has to be properly aligned. If you use a separate CS pin, you can simply use spi.read_into(). spi.read_into(buf) adc = ((buf[0] << 8) | buf[1]) >> x) & 0xfff x should be a value between 1 and 3. Best is to determine it experimentally. The conv variable and write_readinto() is only used to create the CS signal at the MOSI pin. By using an appropriate pattern for conv, like 0x8000, 0xc000, of 0xe000, you can shift the CS signal in clock steps, making the final shift of the result obsolete. So doing that save a pin and saves a few instructions.
  • 0 Votes
    25 Posts
    4k Views
    S
    @robert-hh OK, I set up some code to try this out, several timers at different periods and several threads including one to start LTE, send an SMS and then deinit. From what I can see, the timers do NOT get interupted by the LTE device. It seems the timer counts are retained and dumped to REPL as soon as possible (buffered apparently). There is some corruption/mixup of REPL lines but all the timer flags are there I will investigate a bit further and see if I can use this to my advantage. One thread/timer I will need will be at 11uS preferably, so as it is too fast to capture by eye, I'll have to write to a file to a file to evaluate any impact by the LTE device. Biggest constraint might be the actual time to write to disk. A FIFO data buffer is probably a good solution - some work to do there. The test code was pretty rough and ready so its needs a lot of refinement to be truly useful as a valid test.
  • RGB LED + SPI not working

    WiPy 2&3 rgbled spi wipy
    3
    0 Votes
    3 Posts
    486 Views
    M
    Stupid mistake, I thought I had checked the pinout... thanks! Set it to None and now it works.
  • 1 Votes
    8 Posts
    1k Views
    S
    @robert-hh Thanks, I am working on a very small laptop so I didn't see that as it wasn't very obvious :-)
  • Controlling NeoPixel LED

    SiPy led spi library
    9
    0 Votes
    9 Posts
    1k Views
    robert-hhR
    @brossingo I simplified the neopixel demo code using RMT a little bit. Also, I made a similar short function using SPI. It works to some extend (better than the other SPI driver), but the problem is the unpredictable timing of SPI. It had gaps between the words it sends, which the disturbs the communication. Here is the RMT variant from machine import RMT from time import sleep def send_rmt(data, rmt): from time import sleep_us no_pixel = len(data) bits = bytearray(no_pixel * 24 * 2) duration = bytearray(no_pixel * 24 * 2) index = 0 for pixel in data: for byte in pixel: mask = 0x80 while mask: bits[index] = 1 bits[index+1] = 0 if byte & mask: duration[index] = 8 duration[index+1] = 4 else: duration[index] = 4 duration[index+1] = 8 index += 2 mask >>= 1 sleep_us(60) # wait for the reset time rmt.pulses_send(tuple(duration), tuple(bits)) sleep_us(60) # wait for the reset time data = 6 * [ (127, 0, 0), # green (0, 127, 0), # red (0, 0, 127), # blue ] blank = 24 * [(0,0,0)] rmt = RMT(channel=3, gpio="P11", tx_idle_level=0) while True: send_rmt(data, rmt) sleep(1) send_rmt(blank, rmt) sleep(1) And here is the SPI variant: from machine import SPI, disable_irq, enable_irq from time import sleep, sleep_us def send_spi(data, spi): no_pixel = len(data) buffer = bytearray(no_pixel * 3 * 4) index = 0 for pixel in data: for byte in pixel: bits = 0 mask = 0x80 while mask: bits <<= 4 if byte & mask: bits |= 0x0e else: bits |= 0x08 mask >>= 1 buffer[index] = (bits >> 24) & 0xff buffer[index + 1] = (bits >> 16) & 0xff buffer[index + 2] = (bits >> 8) & 0xff buffer[index + 3] = bits & 0xff index += 4 sleep_us(60) # ensure initial reset state = disable_irq() spi.write(buffer) enable_irq(state) data = 6 * [ (85, 0, 0), # green (0, 85, 0), # red (0, 0, 85), # blue (85, 85, 85), # white ] blank = 24 * [(0,0,0)] spi = SPI(SPI.MASTER, baudrate=3200000, polarity = 0, firstbit = SPI.MSB, bits=32) while True: send_spi(data, spi) sleep(1) send_spi(blank, spi) sleep(1)
  • Does the SPI interface work for anyone?

    Getting Started spi
    7
    0 Votes
    7 Posts
    1k Views
    P
    Re: @paulm Just to note for others. a fix for the SPI issue has finally been snuck in, should be out in the next RC build
  • Spi Slave on WiPy 3

    WiPy 2&3 spi spi slave wipy3.0
    1
    0 Votes
    1 Posts
    382 Views
    No one has replied
  • 0 Votes
    5 Posts
    1k Views
    T
    The argument related issues are related to an issue with using a native class as a base class. See here: https://github.com/micropython/micropython/issues/3323 This doesn't work in Pycom's MicroPython release 1.18 (current stable) but the fix from the above linked issue has been incorporated into the development release 1.20 (currently at rc4). Additionally, the Pycom MicroPython flavor has a different I2C API than the official MicroPython, lacking the I2C methods start(), stop() and write(). There you need to apply the changes outlined in this old thread as well: https://forum.pycom.io/topic/1366/wipy-ssd1306-only-noise/6 Specifically, you'll need to replace the write_data() method with: def write_data(self, buf): self.i2c.writeto(self.addr, bytearray([0x40]) + buf) (I see that you've already discussed the issue with Pycom's MicroPython flavor using framebuf.MVLSB where as the constant is named framebuf.MONO_VLSB in the official MicroPython). The SSD1306 driver in Pycom's MicroPython flavor has never worked and is still using non-existant APIs and constants even in the release-candidate tree: https://github.com/pycom/pycom-micropython-sigfox/blob/release-candidate/drivers/display/ssd1306.py If you get noisy display you might have an SH1106 display. I'm using the below piece of code successfully with random eBay 0.96" and 1.3" I2C OLED displays. It's been a few years since I looked into this but IIRC the SH1106 module's internal memory layout is for 132 pixel strides but the screen only supports 128. So the noise in the form of random black pixels come from the fact that those extra two pixels on the left and on the right side are not accounted for (the display is centered somehow). from ssd1306 import SSD1306 class SH1106_I2C(SSD1306): def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False): self.i2c = i2c self.addr = addr self.temp = bytearray(2) super().__init__(width, height, external_vcc) # Parent does show() but is using the SSD1306 implementation.. self.show() def write_cmd(self, cmd): self.temp[0] = 0x80 # Co=1, D/C#=0 self.temp[1] = cmd self.i2c.writeto(self.addr, self.temp) def write_data(self, buf): self.i2c.writeto(self.addr, bytearray([0x40]) + buf) def poweron(self): pass def show(self): for page in range(8): self.write_cmd(0xb0 | page) self.write_cmd(0x02) # Start addr low column self.write_cmd(0x10) # Start addr high column mv = memoryview(self.buffer) self.write_data(mv[128*page: 128 + 128*page]) from sh1106 import SH1106_I2C i2c = I2C(0, I2C.MASTER, baudrate=400000) d = SH1106_I2C(128, 64, i2c) d.text('ping', 1, 2) d.show()
  • Using SPI on SyPy

    Discussion spi sypy
    6
    0 Votes
    6 Posts
    887 Views
    A
    @robert-hh Unfortunately not although I have converted the code to Arduino C++ and used it on an Adafruit Feather with no problem.
  • SPI read method

    Discussion spi
    5
    0 Votes
    5 Posts
    1k Views
    danD
    Hi @dmayorquin and @robert-hh, I have updated the docs, thanks for pointing it out!
  • 0 Votes
    1 Posts
    479 Views
    No one has replied
  • 0 Votes
    2 Posts
    713 Views
    J
    Hi @asavvin Other than 3.3V and GND there aren't any fixed set of pins for that, it's whatever the code you use expects. For example in my case I used these RST = Pin('P19') DC = Pin('P20') BUSY = Pin('P18') CS = Pin('P4') CLK = Pin('P21') DIN = Pin('P22') But you'll need to use whatever your code is set to.
  • SPI pins..any limits

    LoPy lopy spi
    2
    0 Votes
    2 Posts
    676 Views
    sebS
    Pins P13 to P18 are input only so these can only be used for MISO, not MOSI, CLK or CS.
  • 0 Votes
    9 Posts
    2k Views
    P
    @seb Thanks! Someone should fix this in doc. I'm running the latest stable firmware on wipy3, SPI device is hooked to default pins (as in pinout diagram) and it wasn't working until I've explicitly passed them in pins during SPI initialization. Most of the day yesterday I was struggling to make it work.
  • 0 Votes
    5 Posts
    1k Views
    sebS
    Thanks for porting this over, great work!