Hi, I code a program for my autonomous robot. I am sending numbers from 0 to 8 from Raspberry pi to Arduino through Serial communication. I have Rasp code. But arduino code has some problems. Please can you tell me how to write it best? I want to use switch statement to choose direction for my robot/motors. But when I compile that code to arduino on robot - my robot start doing only default commands. Please why????
**Return char ** Hi, thanks for response, I change a littlebit my code and now I have char as options in switch. But I don’t know if I can return char instead of returning integer, in function in raspberry pi to receive that char in arduino can you help me if this is possible?
You are probably sending from the Pi values that are between 0 and 8 in ASCII not in decimal or base 10. Your tests are based on the decimal or base 10 value, not on the ASCII values.
In this case, the if statement would be true. Also, value and value2 would be equal. If you change your values in your switch from 0 to ‘0’ through 8 ‘8’ and it begins to work, that will be the reason.
I have one question…But I have a code in raspberry pi, in which I measure sonar values - distance and send char to arduino - but in that function (on rasp) I’m returning INT (integer). Is that a problem? I think yes, how can I solve that?
Can I return in rasp functions char - and send it to arduino and recieve char - ‘0’ and it will work
OR
Can I return in rasp functions int - and send it to arduino and recieve it like number I want and it will work (for example - near robot isn’t any obstacle so robot can move forward - Rasp send 1, Arduni recieve it and in function switch it read that robot have to go forward.
So it is char vs int, which I have to use and where please?