I want to connect an rs232 Relais board to my Arduino, thats the first step. The second will be to add an Webserver function, but lets start with the Relaisboard first.
I have two of those Boards (and some older Version which dont support function 4 and 5).
Now my try was the following
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
byte a= 3;
byte b =0;
byte c=48;
byte d= a^b^c;
void setup() {
Serial.begin(19200);
}
void loop() {
// read the input on analog pin 0:
// print out the value you read:
Serial.write(a);
Serial.write(b);
Serial.write(c);
Serial.write(d);
delay(500); // delay in between reads for stability
}
That board is ment to connect with a PC, not with an Arduino board.
Is a schematic of that board available ?
Is it using the higher voltage RS232 ? Perhaps the Arduino is already damaged. The Arduino can only handle 5V level serial communication.
With so little information it is almost impossible to make it work.
I read that a null-modem is required sometimes.
So the board is too expensive, almost useless, and without proper documentation.
And even if you have the hardware correct, you have to send commands.
Thanks for your reply. Yes, the Board is crappy designed but I just got 4 of them for free, so I wanted to give it a try
I managed to get it to work.
There is an Attiny2313 on the board to set the Relais. I already tried to flash the Attiny but it doesnt really work out, so I flashed it back.
The reason why it didnt work to use the RX/TX Output directly on the boards connection is the MAX232 Chip. I soldered my wires directly to the Attiny 2313 and it worked!
Here is my function I used (using Myserial)
void sendCommand(int command, int cardAddr, int data){
byte bytes[4];
bytes[0] = byte(command);
bytes[1] = byte(cardAddr);
bytes[2] = byte(data);
bytes[3] = bytes[0] ^ bytes[1] ^ bytes[2];
writeBytes(bytes,4);
delay(250);
}
void writeBytes(byte arr[], int len){
for(int i = 0; i < len; i++){
mySerial.write(arr[i]);
}
}
First you have to Initialise them (1.0.0) then Set them (3.0.x). Works good.
The next step is Adding the Webserver capability. I already tested it using the simpled Webserver youll find when googling "ArduinoWebServerLED".
I wanted to use the SDcard to store my Website, but how can I do that? I already found "TinyWebServer" but even the examples it wont compile
SimpleWebServer.ino:11:19: warning: Flash.h: No such file or directory
SimpleWebServer.ino: In function 'boolean index_handler(TinyWebServer&)':
SimpleWebServer.ino:38: warning: only initialized variables can be placed into program memory area
SimpleWebServer:38: error: no match for 'operator<<' in 'web_server << (const __FlashStringHelper*)({...})'
SimpleWebServer.ino: In function 'const char* ip_to_str(const uint8_t*)':
SimpleWebServer.ino:48: warning: embedded '\0' in format
SimpleWebServer.ino: In function 'void setup()':
SimpleWebServer.ino:54: warning: only initialized variables can be placed into program memory area
SimpleWebServer:54: error: expected `)' before 'FreeRam'
SimpleWebServer:54: error: expected `)' before ';' token
SimpleWebServer.ino:72: warning: only initialized variables can be placed into program memory area
SimpleWebServer:72: error: no match for 'operator<<' in 'Serial << (const __FlashStringHelper*)({...})'
SimpleWebServer.ino:76: warning: only initialized variables can be placed into program memory area
SimpleWebServer:76: error: no match for 'operator<<' in 'Serial << (const __FlashStringHelper*)({...})'
SimpleWebServer.ino:79: warning: only initialized variables can be placed into program memory area
SimpleWebServer:79: error: no match for 'operator<<' in 'Serial << (const __FlashStringHelper*)({...})'
Are there any Libraries I can use? Is there "ONE" library everyone uses for those Webservers (using SD-Card for switching pins or sth.)?
Below is some test code that basically stores a "web site" on a microSD card. If your relay board uses a max232 or similar chip to convert the pc rs232 signal to TTL, then connect the arduino tx/rx to the TTL tx/rx lines down stream of the chip.
//zoomkat 2/26/13
//SD server slider test code
//open serial monitor to see what the arduino receives
//browser address will look like http://192.168.1.102:84/servosld.htm when submited
//for use with W5100 based ethernet shields
//put the servosld.htm, slider.js, bluev_sl.gif,
//and bluev_bg.gif on the SD card
//download flies at:
// http://web.comporium.net/~shb/pix/servosld.htm
// http://web.comporium.net/~shb/pix/slider.js
// http://web.comporium.net/~shb/pix/bluev_bg.gif
// http://web.comporium.net/~shb/pix/bluev_sl.gif
//
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod; // create servo object to control a servo
Servo myservoe, myservof, myservog; // myservoh not used due to lack of another free pin
String readString, pos;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
//////////////////////
void setup(){
Serial.begin(9600);
// disable w5100 while setting up SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Starting SD..");
if(!SD.begin(4)) Serial.println("failed");
else Serial.println("ok");
Ethernet.begin(mac, ip, gateway, gateway, subnet);
//delay(2000);
server.begin();
Serial.println("Ready");
myservoa.attach(2); //the pin for the servoa control
myservob.attach(3); //the pin for the servob control
myservoc.attach(5); //the pin for the servoc control
myservod.attach(6); //the pin for the servod control
myservoe.attach(7); //the pin for the servoa control
myservof.attach(8); //the pin for the servob control
myservog.attach(9); //the pin for the servoc control
//myservoh.attach(10); //the pin for the servod control
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
//select proper header for file to be sent to browser
client.println("HTTP/1.1 200 OK"); //send new page
if(readString.indexOf("servosld") >=0) {
client.println("Content-Type: text/html");
client.println();
}
if(readString.indexOf("slider") >=0) {
client.println("Content-Type: application/x-javascript");
client.println();
}
if(readString.indexOf("bluev") >=0) {
client.println("Content-Type: image/gif");
client.println();
}
//select file to send to browser
if(readString.indexOf("servosld") >=0) {
File myFile = SD.open("SERVOSLD.HTM");
if (myFile) {
byte clientBuf[64];
int clientCount = 0;
while (myFile.available())
{
clientBuf[clientCount] = myFile.read();
clientCount++;
if(clientCount > 63)
{
client.write(clientBuf,64);
clientCount = 0;
}
}
if(clientCount > 0) client.write(clientBuf,clientCount);
myFile.close();
}
}
if(readString.indexOf("slider") >=0) {
File myFile = SD.open("slider.js");
if (myFile) {
byte clientBuf[64];
int clientCount = 0;
while (myFile.available())
{
clientBuf[clientCount] = myFile.read();
clientCount++;
if(clientCount > 63)
{
client.write(clientBuf,64);
clientCount = 0;
}
}
if(clientCount > 0) client.write(clientBuf,clientCount);
myFile.close();
}
}
if(readString.indexOf("bluev_sl") >=0) {
File myFile = SD.open("bluev_sl.gif");
if (myFile) {
byte clientBuf[64];
int clientCount = 0;
while (myFile.available())
{
clientBuf[clientCount] = myFile.read();
clientCount++;
if(clientCount > 63)
{
client.write(clientBuf,64);
clientCount = 0;
}
}
if(clientCount > 0) client.write(clientBuf,clientCount);
myFile.close();
}
}
if(readString.indexOf("bluev_bg") >=0) {
File myFile = SD.open("bluev_bg.gif");
if (myFile) {
byte clientBuf[64];
int clientCount = 0;
while (myFile.available())
{
clientBuf[clientCount] = myFile.read();
clientCount++;
if(clientCount > 63)
{
client.write(clientBuf,64);
clientCount = 0;
}
}
if(clientCount > 0) client.write(clientBuf,clientCount);
myFile.close();
}
}
delay(1);
//stopping client
client.stop();
//process GET string request from client and and position servo
pos = readString.substring(8, 12); //get the first four characters
//Serial.println(pos);
int n = pos.toInt(); //convert readString into a number
Serial.println(n);
Serial.println();
if(readString.indexOf("?0") >0) myservoa.writeMicroseconds(n);
if(readString.indexOf("?1") >0) myservob.writeMicroseconds(n);
if(readString.indexOf("?2") >0) myservoc.writeMicroseconds(n);
if(readString.indexOf("?3") >0) myservod.writeMicroseconds(n);
if(readString.indexOf("?4") >0) myservoe.writeMicroseconds(n);
if(readString.indexOf("?5") >0) myservof.writeMicroseconds(n);
if(readString.indexOf("?6") >0) myservog.writeMicroseconds(n);
//only seven servo pins, so back to myservoa for testing
if(readString.indexOf("?7") >0) myservoa.writeMicroseconds(n);
//clearing string for next read
readString="";
pos="";
}
}
}
}
}