I have made a very basic test circuit for the opto coupler H11L1 ('similar'datasheet: http://www.datasheet4u.com/datasheet/H/1/1/H11L1_MotorolaInc.pdf.html))
I use the test circuit:
simulate this circuit – Schematic created using CircuitLab
The LED and 470 ohm resistor is only for testing. U1 is the Arduino (software serial pin 9/11) and U2 is the H11L1.
The LED is flashing similar to the RX led on the Arduino.
Also I tested before in an even simpler circuit that the signals from the H11L1 pass through pin 4 (although inverted, which seems to be normal).
However, I don't receive any data in the Arduino (I tried different Arduinos, different speeds, different H11L1).
The data I receive from the (hardware) serial/debug terminal:
0
0
0
0
etc.
My sketch:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 11); // RX, TX
void setup()
{
Serial.begin(9600);
mySerial.begin(300);
}
void loop()
{
mySerial.write('A');
while (mySerial.available())
{
Serial.println(mySerial.read());
}
delay(100);
}
How can I get the correct signal? (meaning 'A' are printed instead of 0's?
Update
New sketch (not having the duplex problem):
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX
void setup()
{
Serial.begin(115200);
mySerial.begin(115200);
}
void loop()
{
Serial.print("Write: A ");
mySerial.write('A');
while (mySerial.available())
{
Serial.print((int) mySerial.read());
}
Serial.println("");
delay(100);
}
Output:
Write: A
Write: A
Write: A
Write: A
etc.
Update
Problem solved: I put it in an answer for clearity.