Page 1 of 1

CAN Communication Problem OPENMV CAM M7

Posted: Wed Aug 29, 2018 7:27 am
by zenertek
Hello,

I am using 'openmv cam m7' at motion detection project. I have to send data with CANBUS to other nodes. But I have getting some error. CAn you help me with this?

Code: Select all

# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!

import sensor, image, os, time, pyb
from pyb import  UART, CAN

TRIGGER_THRESOLD = 5
p_x = 320
p_y = 240

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.set_windowing((p_x, p_y))
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
sensor.set_auto_whitebal(False)
clock = time.clock()                # Create a clock object to track the FPS.

#canbus communication config
can = pyb.CAN(2, CAN.NORMAL)
can.init(pyb.CAN.NORMAL, extframe=False, prescaler=18, sjw=1, bs1=8, bs2=3) #250kb/s
# APB1 = 54MHz, Prescaler 18 et 250kB/s --> 12 time quanta par bit (1 + 8 + 3 = 12)
#uart communication config
uart = UART(1)
uart.init(1152000, bits=8, parity=None, stop=1, timeout=1000, flow=0, timeout_char=0, read_buf_len=64)

#bacground image take and save to sdcard
if not "temp" in os.listdir(): os.mkdir("temp")
sensor.skip_frames(time = 2000)
bgImage = sensor.snapshot()         #.save("temp/bg.bmp")
#bgImage.save("temp/bg.bmp")

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.

    img.difference("temp/bg.bmp")


    hist = img.get_histogram()
    diff = hist.get_percentile(0.99).l_value() - hist.get_percentile(0.90).l_value()
    triggered = diff > TRIGGER_THRESOLD


    print(clock.fps(), triggered)              # Note: OpenMV Cam runs about half as fast when connected
                                               # to the IDE. The FPS should increase once disconnected.

Re: CAN Communication Problem OPENMV CAM M7

Posted: Wed Aug 29, 2018 12:35 pm
by kwagyeman
Hi, I bought the hardware to validate CAN bus communication but I have yet to actually check operation. The hardware on the MCU is definitely there and MicroPython supplies a driver for it but I can't tell you if anything works or not just yet. If you need CAN right now I'd recommend you to connect an Arduino or something to the OpenMV CAM via a UART and use the Arduino as a CAN bridge device.

Re: CAN Communication Problem OPENMV CAM M7

Posted: Wed Aug 29, 2018 12:50 pm
by zenertek
Ok than. Thank you for information.

Re: CAN Communication Problem OPENMV CAM M7

Posted: Mon Sep 03, 2018 3:35 pm
by bauer-san
@zener, which error do you get? Is the error coming from the import line

Code: Select all

from pyb import  UART, CAN
Which firmware are you using?

Re: CAN Communication Problem OPENMV CAM M7

Posted: Thu Sep 06, 2018 2:46 pm
by Erik
I can vouch for CAN working on the M7, I've been using it without any issues.
Your code seems fine, apart from the fact that you never use the CAN bus to send or receive messages.
Echoing the questions from @bauer-san, what firmware are you using and what errors are you seeing?

Re: CAN Communication Problem OPENMV CAM M7

Posted: Thu Sep 06, 2018 3:00 pm
by iabdalkader
Hi everyone, please see this issue:

https://github.com/openmv/openmv/issues/370

The CAN module was disabled by mistake in the last release, and it has been fixed and will be available in the next release. For now you can either use FW 3.0.0 or wait for 3.2.0