can.py

# Questo lavoro è concesso in licenza MIT.
# Copyright (c) 2013-2024 OpenMV LLC. Tutti i diritti riservati.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Esempio CAN Shield
#
# Questo esempio dimostra le comunicazioni CAN tra due fotocamere.
# NOTA: sono necessari due shield transceiver CAN e un cavo DB9 per eseguire questo esempio.

import time
from machine import CAN

# NOTA: impostare su False sul nodo ricevente.
TRANSMITTER = True

can = CAN(0, CAN.NORMAL, baudrate=1000000, auto_restart=True)

if TRANSMITTER:
    while True:
        # Invia il messaggio con id 1
        can.send("Hello", 1, timeout=100, extframe=False)
        time.sleep_ms(1000)

else:
    # Viene eseguito sul nodo ricevente.
    # Impostare un filtro per ricevere messaggi con id=1 e 2
    # Indice del filtro, modalità (DUAL, ecc.), FIFO (0), parametri
    can.setfilter(0, CAN.DUAL, 0, [1, 2])

    while True:
        # Ricevere messaggi sulla FIFO 0 (ce n'è solo una)
        print(can.recv(0, timeout=10000))

results matching ""

    No results matching ""