Hello,
Has anyone tried this sketch and got it to work?
//Created August 15 2006
//Heather Dewey-Hagborg
//http://www.arduino.cc
#include <ctype.h>
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
byte rx = 6;
byte tx = 7;
byte SWval;
void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
SWprint('h'); //debugging hello
SWprint('i');
SWprint(10); //carriage return
}
void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit9600Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit9600Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit9600Delay);
}
int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit9600Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit9600Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit9600Delay);
delayMicroseconds(bit9600Delay);
return val;
}
}
void loop()
{
SWval = SWread();
SWprint(toupper(SWval));
}
I'm thinking either my rs232 to ttl circuit is incorrect or this sketch doesn't work. I've used both electrolytic and non-electrolytic capacitors with no luck. I've also tried two different transceivers (one was on a pcb itself and the other I had on my breadboard).
I was able to display non-sense characters so I changed the baud rate but that didn't help. Also, in the example files the SoftwareSerial file isn't there (which made me think maybe it doesn't work (lol)).
Do you guys think I should buy an RS232 to TTL pcb on ebay for $ 7.50 USD plus shipping? That way, I can quickly isolate the problem?
Please let me know what you honestly think.
And if anyone has had a similar situation in the past
and got their project to work, PLEASE POST A SKETCH
IF POSSIBLE. THANKS.