Possible, but keep in mind that devices which you normally connect to a comport of a pc, don't work with 0-5volt, but -3 to 15 volts to communicate. Connecting arduino-pins directly to a PC-port might ruin the arduino and/or comport.
By using a max232-chip (or similar), that converts signals from an RS-232 serial port to signals suitable for use in TTL compatible digital logic circuits, you'll be safe.
Looks like the Ethernet Shield connects over the SPI interface so the Tx/ Rx lines on the UNO should be free. They are the pins labeled Tx and Rx on the board, pins 0 and 1 if I remember correctly. If you are using 5v logic devices then you shouldn't need the max232 chip, just connect the data lines directly. Don't forget that the Tx line from the UNO goes to the Rx line of the connected device and visa versa.
david1234:
I'm trying to connect the Arduino to many devices that work with RS232 -but all of them work on 5V - do I still need the max232-chip ?
I'm not sure what you mean with "-but all of them work on 5v-".
When the devices communicate at ttl-level (0-5 volt) you should be able to connect them without max232-chip. When the devices themselves are powered... by 5 volt, it still is a question whether the communication also happens at TTL-levels.
Could you tell what devices (type/model) you want to talk to ?
david1234:
and also I'm using the Arduino UNO with ethernet shield - which pins are the Tx,Rx,gnd of the RS232?
or I can't use the shield with the rs232?
It should be possible to use an ethernetshield and use the serial port as well.
You can look at the arduino to see which pins are rx (0)/tx(1) and gnd (no number). But I don't know which pins are used on the devices you want to talk to.
I'm trying to "talk" with 9602 SBD Power Tray .
the wire connection I can understand - but is the code that I need ?
for start
I want the Arduino to send this
at+csq
-- the SBD will send a number 0-5
I will see the number in the Arduino and then
if the answer >1 --> pin5,high (will light a led )
I want to control the arduino from the computer (for start)
and make a program that ask a question and wait from response from me
so I have another question about MAX232
I'm using this scam? - this is what I need t build
david1234:
I'm trying to "talk" with 9602 SBD Power Tray .
I'm not familiar with that but It looks as if it uses an AT command syntax. In that case you just need some code to send a command string to the device and validate the response. This is similar to the way many modems are driven and you should have no trouble finding examples. For example, cellular shields typically use this approach.
You still don't seem to be clear whether the devices you're talking to are using TTL serial or RS232 serial. It's fundamentally important that you get this right, and there's no point buying an RS232 driver if the device actually uses TTL levels.
Im trying to make something simillar with different device... so i have question
You still don't seem to be clear whether the devices you're talking to are using TTL serial or RS232 serial. It's fundamentally important that you get this right, and there's no point buying an RS232 driver if the device actually uses TTL levels.
What bad can happen if the device is allredy using TTL and i put one more between that device and arduino ?
Is there any way to find do i need to put TTL between that device and arduino ?
psyazax:
If there any way to find do i need to put TTL between that device and arduino ?
If the device uses TTL signaling (with the same TTL voltage levels as your Arduino) then it can be connected directly. If the device uses RS232 signaling then you need to use a TTL-to-RS232 adapter with your Arduino on the TTL side and your device on the RS232 side.
If you connect an Arduino directly to a device that uses RS232 signaling, you are likely to damage the Arduino. If you have a device that has a TTL interface and connect it to an RS232 adapter, you are likely to damage the device. You need to know and understand the characteristics of both sides of the interface end ensure that they are compatible before you connect them together.
david1234:
I want to control the arduino from the computer (for start)
and make a program that ask a question and wait from response from me
so I have another question about MAX232
I'm using this scam? - this is what I need t build Travel & Work VISA Agency — SCHOLARSHIP IN CANADA
thanks
That's indeed a schematic that should work. If you do want to talk to the arduino with PC, question will be how to do it. If you do it over ethernet, the schematic is OK. If you want to address the Arduino using usb, you'll need to choose two other arduino pins and use the softwareserial library to create a second Serial port. Arduino already uses pins 0 and 1 to communicate over USB.
o.k.
so I need to "open" anther serial communication with the Arduino?
did it using softweresireal
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
but I want it to be able to send\get string of 8 characters
how do I do this?
david1234:
I want it to be able to send\get string of 8 characters
how do I do this?
The process of sending and receiving sequences of characters is trivial. The sender calls serial.write or serial.print, and the receiver calls serial.available and serial.read. The tricky part is that typically you want the receiver to treat those eight bytes as a message, and not just a sequence of bytes. In other words, out of the sequence of bytes you're receiving you need to know where each message starts and ends. The usual way to achieve that is by using a message delimiter - a byte value that you can recognise as being the boundary between messages. Where your message consists of ascii text as in this case, good values for the delimiter are a newline ('\n') character, or null (zero, '\0'). Using the delimiter approach your receiver would read and buffer the received characters until the delimiter arrived, and then process the content of the buffer and clear the buffer ready for the next message. When using textual messages, I would recommend buffering the message as a c-string in a null-terminated char array. You'll see the code for this time and again, and it usually looks something like this:
if(mySerial.available())
{
char c = mySerial.read();
if(c == '\n')
{
// end-of-message marker received
if(bufferCount > 0)
{
processMessage(buffer);
bufferCount = 0;
}
}
else
{
if(bufferCount < (bufferSize-1)) // -1 allows space for the null terminating char
{
buffer[bufferCount++] = c;
buffer[bufferCount] = 0;
}
else
{
// buffer overflow - discard received character
}
}
}
I'm trying and trying - without any success
I see that I send to the modem "at"
and the modem need to return OK
but I can't see this in the monitor serial
can you help me ?(again....)
I don't know what I'm doing wrong
I got lost totally.
what does this program do - "processMessage"?
also how do I save char in the buffer?
Thanks ,
this is what I wrote so far - to many errors
#include <SoftwareSerial.h>
#include <PString.h>
int ledPin=13;
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
Serial.begin(9600); // Open serial communications and wait for port to open:
delay(1500);
Serial.println("Ready to work!");
mySerial.begin(19200);
mySerial.println("AT");//just to see that its working
pinMode(ledPin, OUTPUT);
}
void loop()
{//start loop
mySerial.println("AT");
//delay(5000);
if (mySerial.available())
Serial.write(mySerial.read()); //print in ARD what device send
String buffer();
int bufferCount=0;//starting count for msg
int bufferSize = 6 ;//max char of msg
if(mySerial.available())
{
char c = mySerial.read();
if(c == '\n')
{
// end-of-message marker received
if(bufferCount > 0)
{
// processMessage(buffer);
bufferCount = 0;
}
}
else
{
if(bufferCount < (bufferSize-1)) // -1 allows space for the null terminating char
{
buffer[bufferCount++] = c;
buffer[bufferCount] = 0;
}
else
{
// buffer overflow - discard received character
}
}
}
}
The sketch so far is very confused. You're sending another command each time loop() is called, without waiting for the previous response to be processed. The code trying to buffer the response is an odd mixture of c-strings (char arrays) and the String class, and presumably won't evencompile. And you have commented out the code to process the buffered message, so it will be silently discarded anyway - except for the odd character which might be picked up by that first call to mySerial.read().
Since you don't seem to have got as far as receiving any response from the modem yet, I suggest you forget about parsing the responses for now and just concentrate on displaying them so y0ou can confirm you are actually getting a response. That can be done with a simpler sketch:
// untested
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup()
{
Serial.begin(9600); // Open serial communications and wait for port to open:
delay(1500);
Serial.println("Ready to work!");
mySerial.begin(19200);
delay(1500);
mySerial.println("AT");//just to see that its working
}
void loop()
{
if (mySerial.available())
{
Serial.write(mySerial.read()); //echo the response to the serial monitor
}
}