Interfacing a USB/serial device with Arduino USB/serial interface - serial-port

On one side I have a device with a USB (FTDI chip) interface communicating in serial 9600bps,N,8,1 - the default configuration for the Arduino USB/serial interface.
On the other side I have a simple Arduino sketch that starts a serial session and transmits data.
void setup() {
// put your setup code here, to run once:
Serial.begin(9600,SERIAL_8N1);
}
void loop() {
// put your main code here, to run repeatedly:
char* data_to_send="66";
SSEND(data_to_send);
delay(5000);
}
String SSEND(char* data){
String protocol="AT$SF=";
protocol+=(String)data;
// protocol+="\r";
Serial.println(String(protocol));
delay(1000);
return "OK";
}
The sketch works just fine when connected to the computer.
Then I try to connect to the device and I see the Tx LED that stops blinking so it doesn't send anything and of course the device doesn't work like expected. Besides, I tried sending serial commands directly from the computer to the device and it works just fine.
So my questions are:
Why does the serial interface between Arduino and my device doesn't work?
Why does Arduino stop sending data once the USB/serial interface switched from the computer to the device
What would be the solution to make the device work with the Arduino?
Should I switch the TX & RX with a splitted FTDI cable plugged to port 0 and 1?
Thanks for your help

I suspect that device is a USB device and not a USB host, and you plugged two USB devices together. That Arduino is not a USB host, and a USB connection always needs a host.
The plug adapter you're using is not even supposed to exist according to the USB spec, because the different shapes of plugs are specifically there to make it impossible to plug two devices into each other like you've done here.
The way to make it work would be to use another board that actually supports acting as a USB host.

Related

Use the Arduino Nano's serial interface to communicate with ESP8266 -- currently hangs

I have designed a ledstrip driver capable of receiving commands over UDP-IP. I initially worked with an Arduino MEGA, and currently I'm in the process of deploying the code in an Arduino NANO.
The Arduino NANO only has one hardware serial interface, unlike the MEGA, which has several. This forces me to disable the usual debugging through one of the Serial ports (by sending strings to the computer) and to reserve the one and only serial interface for the ESP8266. In short, I am connecting the ESP8266 to the TX and RX pins in the NANO.
I am aware that I could use the softwareserial.h library, but I'd like to avoid it if possible.
The following function sets up the Wifi object:
void wifi_setup(){
// Initialize serial for ESP module
Serial.begin(9600);
// Initialize ESP module
WiFi.init(&Serial); /* GETS STUCK HERE */
...
}
The problem is: the microcontroller gets stuck in the Wifi.init() function and never abandons it.
I am aware that the serial interface is connected to the USB port, and am suspicious this might be a problem. However, I have tried giving power to the NANO through the VIN pin instead of through the USB port, and it hasn't worked.
What am I doing wrong?
The best solution will be to write separate code for ESP8266 and Arduino Nano - or even only for ESP8266 (NodeMCU to make it easy). It will be much easier. But if you really want to do it in your way, i think ESP uses 115200 baud, and you've set it to 9600.

how to get AT response from ESP8266 connected to arduino

I am fighting with ESP8266 wifi module and connecting arduino. After updating firmware to newest version i started to programm arduino to get data incoming from wifi. I saw many examples about maiking webserver via ESP8266 but none of them works for me.
ESP is connected to my Arduino Leonardo:
>
Arduino -> ESP8266
power 3.3V -> vcc
ground -> ground
tx -> rx (via logic level converter 5->3.3V)
rx -> tx (via logix level converter
power 3.3V ->gpio0 (without any resistors)
I made simple sketch:
void setup(void){
Serial.begin(9600);
Serial1.begin(115200);
}
void loop() {
if(Serial1.available())
{
Serial.println("WIFI IS AVAILABLE");
Serial1.println("AT");
delay(1000);
} else {
Serial.println("WIFI not available.");
delay(1000);
}
}
After executing it ESP8266 is powered (red led is on) and also every second blue led (blinks). That makes me sure that in fakt "AT" command is transmited to module. But there are also two issues:
i want to get response from esp - in this case word "OK". I tried Serial1.read() but it only reads one byte. Serial1.readString() makes my messages "wifi not available" and sametimes "wifi is available" as if for a while the connection would be unavailable
after uploading sketch to arduino and having powered esp8266 wifi module is always unavailable - i need to power the module off and on again to have it working.
Anybody please can help me?
What you need to do is change your approach a bit. Do not check if data is available. The trick is to send the module something and then check for data.
Do something like:
while (Serial.available() > 0)
Serial.read();
to clear the buffer before any command you want to send. Then send the command. Then check for data as a response.
Do not rely on that Blue LED as any indication. It is only an indication that the ESP8266 is busy using the WiFi in some sort of way, whether it is doing keepalives, initializing WiFi or whatever. It can be totally unrelated to whatever you are sending. If you do not receive a valid response then you must assume that there is comms issues between you and the module. One thing though is that if that Blue LED never goes off then either the module has frozen or the firmware was corrupted. I have had that many times. I then reload the firmware and usually that fixes it. It usually only happens during development times where I reset, upload code or change wires.
I use mine with an atmega328 on a separate slef-built board and not the one on the Uno and run that board on 3.3v itself and then use a logic level converter between that atmega board and my Uno so that I can program it. But I have had sporadic issues with non-comms but I suspect it might be power related. Be aware that running your Serial via the logic level converter might also be causing comms issues.
Proposed wiring: All pins except RX,TX,VCC and GND goes to VCC via 10K pullup resistors. RX goes to the arduino's TX and TX goes to the arduino's RX. Of course you know where VCC and GND goes.

Serial Communication over Desktop to Arduino

I have a USB 2 Serial adapter and the device is working fine. I see the device perfectly configured in my System.
I have connected the TX0 pin of Arduino to DB 2 pin (read pin) of the adapter. Below is my Arduino code:
int i = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
for(i=0;i<6;i++)
{
Serial.write('H');
delay(100);
}
}
But when I try to read thru terminal software of data received at my COM port I see some junk character incoming. I am pretty sure that I am using same baud rate / flow setting both side. Why am I facing this issue - do I need to connect any other pins also as I just need to receive data at system side?
You should connect the ground pin with the ground pin
Arduino Communicate with Ur computer using pins 0 and 1( Tx0 and Rx0)
you shouldn't be connected to the Tx0 pin to another serial device because arduino use it to communicate with computer.
if you are using Uno. Check for Software Serial. and two grounds should be connected.

What happen when use rs232 instead of usb in arduino?

I just start a project which is very basic actually. But I need an information. It is about arduino serial communication. Here is the question.
If I connect arduino to computer using TTL to RS232 converter without USB cable then can I still use serial monitor to get some data or what happens ? Assume arduino is programmed before using usb cable, and it is powered externally when usb is not used.
for instance the code just
Serial.println("It is working");
delay(1000);
Thansk a lot.
you will fry it. Standard RS232 use a +-12V level, while arduino use TTL level (0-5V), so you still need a RS232 -> RS232TTL converter. If you use it, then using virtual serial over USB or real hardware serial is exactly the same, except that hardware serial port never appear/disappear when you plug in the arduino (there is not something like plug'n'play in rs232, it is always plugged)

Arduino: Incoming USB serial data when USB is disabled hoses the connection

I'm writing a sketch for an Arduino Leonardo that occasionally needs to communicate bidirectionally via USB serial, and also needs to be power efficient. To save power I'd like to disable the USB when it's not needed. I can successfully use power_usb_disable() and power_usb_enable() to do this, BUT only if no data is sent to the Arduino when USB is disabled.
Here's how to reproduce the problem: I run the following sketch on the Leonardo while it's connected to a serial comms program on my computer (I've tried the Arduino serial monitor and Minicom in Linux and PuTTY in Windows). It works as expected, printing out the messages, until I type something right after the "Disabling USB..." message. Once I do that, I will receive no further data from the Leo. The funny thing is, the TX and RX LEDs continue to blink as if everything is fine. The only way to get the connection working again is to reset the board.
Now, I don't really care about dropping the incoming data when USB is disabled, that's to be expected...but I would like the serial connection to continue to work correctly once USB is enabled again.
I don't know enough about how USB serial works to know how to troubleshoot this.
#include <avr/power.h>
void setup() {
Serial.begin(9600);
delay(3000);
}
void loop() {
Serial.println("USB is enabled!");
delay(1000);
// If I send characters here, everything is fine.
Serial.println("Disabling USB...");
delay(25);
power_usb_disable();
delay(1000);
// If I send characters here, it hoses the USB connection somehow.
power_usb_enable();
delay(25);
}
I guess for now the best answer to this problem is "don't do that." I can arrange not to disable the USB if the connection is open, using the "if (Serial)" thing. So if somebody has a serial monitor open and looks as if they're about to type something, I leave USB enabled. Seems to work OK, although it doesn't address the underlying general question of how to robustly disable and re-enable USB from any state it might be in. I would still love to hear expert advice on that.

Resources