Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I digitalRead a pin and convert data to String on Arduino?
    text
    copied!<p>I'm doing a communication system with 2 Arduinos Leonardo. To transmit I had to convert a String in bits and send them through a PWM pin. The question is, how can I do the receiver?</p> <p>My idea is to receive data in a digital pin, so I can convert LOW/HIGH to '0' and '1', put 8 bits in a string, convert to char and then I have my final String.</p> <p>Some info: - I'm using PWM because I want to implement FSK modulation, sending bit by bit;- - I have some hardware to get communication system working; - My physical channel for communication is Serial (via Arduino pins); - In the receiver hardware will provide me TTL signals, so I will have 0V/5V. That's why I think digitalRead() should work; - Data is sent via PWM and received in two level signals; - I'll have to do some protocol to send/receive data, but still don't know how...</p> <p>This is the code I wrote:</p> <pre><code>void setup() { Serial.begin(9600); while (!Serial) {;} } void loop() { char bitPosition = 0; String inMessage = 0; while (Serial.available() &gt; 0) { char outChar; boolean digValue = digitalRead(inPin); for(bitPosition = 7; bitPosition &gt;= 0; ){ if(digValue == LOW){ bitWrite(outChar, bitPosition, 0); } if(digValue == HIGH){ bitWrite(outChar, bitPosition, 1); } bitPosition--; } inMessage.concat(outChar); if(inMessage != 0){ Serial.println("Received: " + inMessage); } } } </code></pre> <p>I want this code to transform HIGH/LOW states from digitalRead in a string of characters. 0/1 -> char (outChar) -> String (inMessage). I don't know if i'm not thinking right. Suggestions? Should I have to do something about baudrate to receive/transmit data? How?</p> <p>Any help/suggestion would be appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload