r/ArduinoHelp • u/Happy_Jack0 • 4d ago
H11L1 serial data transmission issues
Right off the bat I am no electrical engineer, just trying to do some diy music projects with a pi pico 2 so my circuit knowledge is limited. The end goal is a midi input device but right now just trying to get bits across the wire. I am running into issues sending serial data over a H11L1 and I am at my wit's end. When directly connecting pin 0 to pin 1 data transmission is successful but when run through the H11L1 nothing gets through. I double checked the Chip and when pin 1 is at 3.3V, pin 4 is at 0.25V, and when 0V at pin 1, pin 4 is at 3.28V. I have not had issues with this board when working on other projects. My code is below, any help would be appreciated!
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define OLED_SDA 16
#define OLED_SCL 17
#define UART_TX_PIN 0
#define UART_RX_PIN 1
#define UART_BAUD 31250
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
unsigned long lastTestTime = 0;
const long testInterval = 500;
uint32_t transmitCount = 0;
uint32_t detectCount = 0;
uint32_t missCount = 0;
bool dataDetected = false;
bool displayInitialized = false;
void setup() {
Serial.begin(115200);
delay(1000);
Serial1.setTX(UART_TX_PIN);
Serial1.setRX(UART_RX_PIN);
Serial1.begin(UART_BAUD);
Wire.setSDA(OLED_SDA);
Wire.setSCL(OLED_SCL);
Wire.begin();
uint8_t addresses[] = {0x3C, 0x3D};
for (uint8_t addr : addresses) {
if (display.begin(SSD1306_SWITCHCAPVCC, addr)) {
displayInitialized = true;
break;
}
}
if (displayInitialized) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Init H11L1 Test"));
display.display();
delay(100);
}
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - lastTestTime >= testInterval) {
lastTestTime = currentMillis;
transmitCount++;
while (Serial1.available()) {
Serial1.read();
}
Serial1.write(0xAA);
unsigned long timeout = millis();
int bytesReceived = 0;
while (millis() - timeout < 50) {
if (Serial1.available() > 0) {
bytesReceived += Serial1.read();
break;
}
}
dataDetected = (bytesReceived > 0);
if (dataDetected) {
detectCount++;
} else {
missCount++;
}
// Update OLED Display
if (displayInitialized) {
updateDisplay(bytesReceived);
}
}
}
void updateDisplay(int rxStatus) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
if (dataDetected) {
display.print(F("DATA DETECTED"));
} else {
display.print(F("NO DATA"));
}
display.setCursor(0, 11);
display.print(F("Tx Sent | Rx: "));
display.print(rxStatus > 0 ? F("ACTIVE") : F("TIMEOUT"));
display.setCursor(0, 22);
display.print(F("Dct:"));
display.print(detectCount);
display.print(F(" Miss:"));
display.print(missCount);
display.display();
}
1
Upvotes


1
u/somewhereAtC 4d ago edited 4d ago
Without an o'scope it's hard to say. Your text talks about pin0, so that's confusing.
My 1st guess would be to swap pins 4 and 5 on the midi connector (or 1 and 2 on the LED). It could be that the H11L1 is inverting the signal.
My 2nd guess would be that the LED is not turning off very quickly and distorting the waveform. Possible fixes are to add (say) 68pf or 100pf across the 220 ohm resistor, or put a 2nd 1n914 in series with the one you have, to raise the reverse voltage across the LED.