OpenMV (Master) - Arduino Mega 2560 (slave) - SPI

Hi,


I would like to send chars from the arduino Mega(slave) to the openMV(Master) using the SPI connection.


I am trying to use the SPI.recv function in the openMV as shown in the code below

import sensor, image, time,pyb

from pyb import SPI
spi = SPI(2, SPI.MASTER, baudrate=115200, polarity=1, phase=0, crc=0x7)
pin = pyb.Pin("P3", pyb.Pin.IN, pull=pyb.Pin.PULL_UP)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

clock = time.clock()

buff = bytearray(4)

while(True):
    clock.tick()
    img = sensor.snapshot()
    print("HEY")

    try:

        # If we failed to sync up the first time we'll sync up the next time.
        #print("Sent Data!") # Only reached on no error.
        print("Ha")
        #print(buff)
        spi.recv(buff,timeout=5000)
        print(buff)

    except OSError as err:
        pass # Don't care about errors - so pass.
        # Note that there are 3 possible errors. A timeout error, a general purpose error, or
        # a busy error. The error codes are 116, 5, 16 respectively for "err.arg[0]".
    while(not pin.value()): pass
    print("END")

And here is the arduino code for testing it

#include <SPI.h>
//#include "pins_arduino.h"


#define SS 53
void setup ()
{
  Serial.begin (115200);

  digitalWrite(SS, HIGH);  // ensure SS stays high for now

  // Put SCK, MOSI, SS pins into output mode
  // also put SCK, MOSI into LOW state, and SS into HIGH state.
  // Then put SPI hardware into Master mode and turn SPI on
  SPI.begin ();

  // Slow down the master a bit
  SPI.setClockDivider(SPI_CLOCK_DIV8);
}




void loop (void)
{
  digitalWrite(SS, LOW);


  SPI.transfer('2');
  delay(1);
}

Please do you think I am missing something?

Thank you!

Hi, your Arduino is not in slave mode there.

I highly recommend serial comms to connect the camera to an Arduino. It is much easier.