Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

H11L1 opto isolator does not pass signal to Arduino (correctly)

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:

schematic

simulate this circuit – Schematic created using CircuitLab

Circuit

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.

Answer*

Draft saved
Draft discarded
Cancel
6
  • I will try with higher baudrates ... also I changed my sketch (but without much improvement). To be honest, I have a Mega, but I don't 'dare' to use it, since that one is now on a breadboard circuit that I'm for sure knows it works (and by disassembling it, I'm afraid I don't have any working solution). I have ordered a new one, and will test it again when I receive it. Commented Jun 25, 2017 at 13:32
  • 1
    To the best of my knowledge, "Software Serial works better with higher baudrates. The lower the baudrate, the more trouble you get" is false. In general, software serial is incapable of handling data rates like 115200 without high incidence of errors. OTOH, it should handle 4800, 9600, etc ok Commented Jun 25, 2017 at 13:32
  • MichelKeijzers, The SoftwareSerial is useless for you, it can not transmit and receive at the same time. @JamesWaldby With lower baudrates, the interrupts are disabled for longer time. With a full sketch and lots of things going on, it will cause a lot of trouble for sure. Commented Jun 25, 2017 at 13:35
  • I tried with 300, 9600 and 115200 (no changes) ... probably the duplex is the main problem ... I will try this test again when I have the new Mega. Commented Jun 25, 2017 at 13:38
  • 1
    In the Arduino IDE, in the Library Manager, search for: altsoft. Install the "AltSoftSerial by Paul Stoffregen". Find which fixed pins are for RX and TX ( pjrc.com/teensy/td_libs_AltSoftSerial.html ). Use 9600 baud, and it should work. Commented Jun 25, 2017 at 13:43

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /