Arduino FastLED [0] .showLeds(255)与i2c不兼容。 Python从RaspberryPi传递的i2c

时间:2019-06-27 05:35:15

标签: python arduino raspberry-pi3 i2c

我是Arduino的新手。为此,我们需要从RaspberryPi更改Arduino变量,因此我们选择了i2c通信。在我们将FastLED[0].showLeds(255)放入Arduino代码之前,它工作正常。它会点亮并导致RaspberryPi中的 I / O错误(错误[5]或错误[121])

# -*- coding: utf-8 -*-

import smbus
import time
# for RPI version 1, use "bus = smbus.SMBus(0)"
bus = smbus.SMBus(1)
time.sleep(2)

# This is the address we set up in the Arduino Program
address = 0x04

def writeNumber(value):
    # bus.write_byte(address, value)
    bus.write_byte_data(address, 0, value)
    time.sleep(2)
    return -1

def readNumber():
    number = bus.read_byte(address)
    time.sleep(2)
    # number = bus.read_byte_data(address, 1)
    return number

while True:
    var = input("Enter 1 – 9: ")
    if not var:
        continue

    writeNumber(var)
    print "RPI: Hi Arduino, I sent you ", var
    # sleep one second
    # time.sleep(1)

    number = readNumber()
    print "Arduino: Hey RPI, I received a digit ", number
    print

当我们禁用行color_chase_side(CRGB::Red, 15);从而禁用FastLED[0].showLeds(255);

时,此代码可以正常工作

void loop() {
  delay(100);

  if(state == 1){
    color_chase_side(CRGB::Red, 15); 
  }
  else if(state == 2){
    another_function(CRGB::Red, 15);
}

}

// callback for received data
  void receiveData(int byteCount){

      while(Wire.available()) {
        number = Wire.read();
        Serial.print("data received: ");
        //Serial.println(number);

        if (number == 1){
          state = 1;
        }
        else if(number == 2){
          state = 2;
        }
        else if(number == 0){
          state = 0;
        }
      }
  }



Change the Fast led functions based on Raspi data.

0 个答案:

没有答案