4D systems dislpay + camera openmv

Hello,

I’m starting to use openmv and i need to know if the camera can works good in mode spi slave. I have tested more things with openmv IDE like for example:
1>>

SPI.init(SPI.SLAVE,polarity=0, phase=1, bits=8, firstbit=SPI.MSB, ti=False, crc=None)

2>>

spi = SPI(2, SPI.SLAVE, baudrate=600000, polarity=0, phase=1)

3>>

spi = pyb.SPI(2, pyb.SPI.SLAVE, polarity=0, phase=1)
     pin = pyb.Pin("P3", pyb.Pin.IN, pull=pyb.Pin.PULL_UP)

but it always give me the same OSError : 16 , and the bus is not busy.

I have the problem with this line of my code too: data = spi.send_recv(b’\xff\xff’). The ide show me the same error. I have tested it changing the pins on hardware but i dont get it works well.


I need your advices and help.


Thank you in advice :confused:

Drogon

Hi, I thought I answered this a while back. Please see the Examples → Board Control → SPI Control Example. It shows how to drive our LCD shield in user space using the SPI code.

Hi,


Yes, i did check this example and i modified repeatedly, my last try is:

import sensor, image, time
from pyb import Pin, SPI

spi = SPI(2, SPI.SLAVE, baudrate=int(1000000000/66), polarity=0, phase=1)

def wait_sync():
    c = 0x00
    while (spi.recv(c) == 0 ):
        print("nothing")
        if (spi.recv(c) != 0 ):
          spi.send(c)
          print ("sync done")
          break

# Display On
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # must be this
sensor.set_framesize(sensor.VGA) # must be this
sensor.set_windowing((320, 240))
sensor.skip_frames() # Let new settings take affect.
clock = time.clock() # Tracks FPS.
print("Settings openmv ok")
while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.
    wait_sync()
    spi.send(img)
    print(clock.fps())

But the openmv ide give me the error 5 (OSError: [Errno 5] EIO) and right now i dont know like i can solve it…


Thank you for your help Nyamekye

Oh, yeah, that’s most likely an STM HAL issue. Just wrap the method with a try and catch stament and retry on an error.

See the pixy emulation example script in SPI mode for how to deal with this. I can provide a more detailed answrr later if you need more help.

Um, these errors are how the MicroPython PYB works. I agree our I/O is hard to use than the Arduino.

Hi,


I have seen the example of pixy with spi but i need more help … my master wait the same byte (0x88) of my slave but i cannot get it. My idea is transfer the image of openmv to my display. At the moment only show the picture.

Can you help me with the script of openmv , please? its complex for me… :confused:


Sorry and thank you so much

Hi, do you have any documentation for the display. I’ll take a look.

That said, I’m generally unable to do coding for folks since I’m way to busy… if you send the documentation I’ll try to give you a write up of what to do but I wouldn’t wait on me for a solution.

Hi,


the documentation: https://www.4dsystems.com.au/product/gen4_uLCD_70D/


I just hope a little help with this…because I cannot get the sync between the two devices…after of this I believe that I’ll be able to get the data through, but the bus error is difficult for me because I don’t understand why happen it.


Don’t worry! I understand it :slight_smile:

Thank you so much for your time!!

Can you post your code using the code tags?


I can’t figure out the indentation. Note that by try and catch I mean you can do this:

def wait_sync():
    while True:
        data = spi.recv(1)
        if data == 0: break
        print("nothing")
    c = spi.recv(1)
    if (c != 0 ):
        spi.send(c)
    print ("sync done")

Note, I don’t see any CS pin in your code. The SPI bus controller doesn’t control the CS pin. It just does SCLK, MOSI, and MISO.

Of course, I can do it. (done)


I have tried your lines and I have added the line <<cs = Pin(“P3”, Pin.OUT_OD)>>because when I saw your comment I saw the line in one of the examples.


Then I have tested all it and only show . :/… any idea?


Thank you for your time again :=)

Hi, did you try the code I posted above?

Note that I don’t have your screen or even know what the protocol is… so, I’m not really sure how to help you…

If you want me to provide some useful answer you kind of need to narrow everything down to “one” line of code which is having the error. From the code you have for doing the sync I think you’re passing the variables to the receive command wrong.

Hi,

Yes, i did test your code but no works because show “nothing”. And I do not have any compilation errors…:confused:

The program on the display to wait the sync is:

 
 func slave_sync()
    var result := 0x00;
    while (result != 0x88)
        pin_LO(PA2); 
        SPI1_Write(0x88);
        result:= SPI1_Read();
        putnum(HEX, result);
        pin_HI(PA2); 
    wend
    //master recv data
    pin_LO(PA2);
    SPI1_Write(0x88 ^ 0xff);
    pin_HI(PA2);
endfunc

But you can explain me more about the variables that you think are worng :=)

Thank you so much for all your help!!!

Okay, so you want something like:

pin = Pin('P1', Pin.OUT_PP, Pin.PULL_UP)
def wait_sync():
    while True:
    	pin .value(0)
    	spi.send(0x88)
        data = spi.recv(1)
        pin .value(1)
        print("%02x" % data)
        if data == 0x88: break
    pin .value(0)
    spi.send(0x88 ^ 0xff)
    pin .value(1)
    print ("sync done")

Please read the docs… http://docs.openmv.io/library/pyb.SPI.html?highlight=spi