Below is a reference to a logical level bi-directional converter (aka level shifter) I purchased on Ebay. I've soldered the 12 pins (6 for each piece) to the level shifter so that it fits on my bread board.
http://www.ebay.com/itm/121868205078?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
This may sound trivial, but I'd like to troubleshoot the level shifter with communication both ways (Rx and Tx) to make sure it's working properly. I've got a constant 4.85v (5V) going to the HV pin, and a constant regulated 3.24V (3.3V) going to the LV pin, along with ground to both GND pins. Right now, I'm using pin0 (Rx) and pin1 (Tx) on the Arduino Mega 2560.
void setup() {
Serial.begin(9600);
}
void loop() {
delay(1000);
Serial.println("Test");
}
How can I test this level shifter without any fancy components? How could I write a program to toggle an LED both on LV1 and HV1 pins, by modifying the program above? Please note, that even though the Arduino runs on 5V, I am not using the Arduino as my HV power source.
EDIT (per comment 3 by @Paul):
Test:
- Burn blank sketch into Arduino
- Connect 5V (Arduino 5V) to HV pin
- Connect GND (Arduino GND) to GND pin on same side as HV pin
- Connect 3.3V to LV pin
- Connect GND (from 3.3V power source) to GND pin on same side as LV pin
- Connect Arduino Tx pin to channel 1 (HV1)
- Connect Arduino Rx pin to channel 2 (HV2)
- Short channel 1 to channel 2 with jumper wire
When all of this is connected, and I open the Serial Monitor on Arduino IDE, anything I type will echo back exactly what I typed. And when I disconnect one of these jumpers, it doesn't echo back. So it seems to work.
2 Answers 2
You don't need to write any program.
First, note that this is (or at least purports to be) an I2C level shifter. This means that it does not actively pull up anything; it only actively pulls down. You are supposed to provide pull-ups somewhere in your circuit.
To test it, pull up HV1 and LV1 with 10K resistors to HV and LV respectively; measure the voltage on both sides to verify you are pulling to ~5V and ~3.3V respectively.
Ground HV1, check that LV1 is low.
Ground LV1, check that HV1 is low.
Ta-dah!
-
The pull-ups are already on the board, as far as I can see. Though, I'm not entirely sure if you can use an I2C level shifter for UART.Gerben– Gerben2016年05月02日 08:25:30 +00:00Commented May 2, 2016 at 8:25
-
@Gerben the resistors, are used for the (bi-directional) voltage conversion. I've got a similiar board (sparkfun.com/products/12009) which works for uart, logic and spi (haven't tried I2C but it should be fine).aaa– aaa2016年05月02日 10:12:43 +00:00Commented May 2, 2016 at 10:12
-
@JayEye - When you say "pull up HV1 and LV1 with 10K resisters" do I put a 10K ohm resister between the HV1 pin and some something else, and another 10K ohm resister between the LV1 pin and something else? Do I need a "something else" or am I just measuring the voltage drop where the "something else" is on the low voltage side and high voltage side of channel 1?JustBeingHelpful– JustBeingHelpful2016年05月02日 13:36:18 +00:00Commented May 2, 2016 at 13:36
-
1at the risk of angering the moderators, I'll point to actual products: adafruit.com/products/1875 for general-puprose shifting, and adafruit.com/products/757 for I2C level shifting. Read the documentation they provide, they'll explain everything you need to know. I am not affiliated with Adafruit; I just find them convenient, as we are both in NYC and even the cheapest shipping results in two-day delivery!!JayEye– JayEye2016年05月02日 19:52:45 +00:00Commented May 2, 2016 at 19:52
-
1No, "pull up" means that it's connected through a resistor to "postive" so that, if no device is driving it low, it will be defaulted to postive. You might want to check some tutorials on it. But, it's not required for communication with Rx/Tx lines.aaa– aaa2016年05月31日 10:03:35 +00:00Commented May 31, 2016 at 10:03
@paul i have done some but when i connect channel1 to channe2 via jumper wire arduino stop working and text stop coming on serial monitor.
from output Tx -> HV1 (high) -> shifter LV1 (to low) -> wire -> shifter LV2 (to high) ->HV2 -> input Rx
if that succeeds, you can safely assume it's working for UART and that it's bi-directional.