0
votes

Hi I have connected my raspberry to arduino via serial USB and on arduino there is a led that I want turn on if in the script in python I send a letter o a number

I have write this code in raspberry Python:

import serial
ser=serial.Serial('/dev/ttyUSB0', 9600)
ser.write('3')

In my arduino I have load this skatch:

const int ledPin = 12;
int val;
void setup(){
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  if (Serial.available())  {
     val=Serial.read();
     if(vale==3)
       digitalWrite(ledpin, HIGH);
  }
  delay(500);
} 
}

When I lunch the script py from rasp, I see that led not turn on, but turn on a onboard led of arduino.

I think that the problem is the type of data like ASCII or integer but I don't understand how to fix. Serial device is ok and is USB0 and the pin of led on arduino is right Please help me

1

1 Answers

0
votes

There is a typo in the if statement, you have put vale instead of val.

ser.write('3')

takes 3 as a string.So try this in the if statement,

if(val=='3')