system
April 30, 2014, 10:11am
1
I there,
I have a project for the school, i have too make some solar panel control board.
I have done everything, the web page to control the UP/DOWN and stop, there is no problem with that,
I have a limit switch button to stop the panel when I push the "down" link on the page, in order to always stop the panel, I wanted to use Attachinterrupt, i have done a debouncing of the limit switch in hardware using resistance, capacitor and Schmitt inverter trigger,
When i do a simple sketch, like on/off of led 13, the sketch work fine, but when I try to use it with the motor shield, nothing work, there link interference I think..
does anyone of you had this problem before ?
thanks, best regards
system
April 30, 2014, 10:39am
3
Hi,
The simple code that work :
int buttonInt = 0; //AKA digital pin 2
void setup()
{ attachInterrupt(buttonInt, x_swap, RISING);
Serial.begin(9600);
Serial.println("VOID SETUP"); }
void x_swap()
{ Serial.println("VOID x_SWAP"); }
void loop()
{ Serial.println("VOID LOOP"); delay(3000); }
My other code with everything :
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xCE, 0xA1 }; //physical mac address
byte ip[] = { 192, 168, 0, 2 }; // ip in lan
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
int switchhh = 2;
int pwm = 5;
int dir = 7;
int valswitch = 0;
void setup(){
//Setup Channel A from Motor shield
pinMode(pwm, OUTPUT); //Initiates Motor Channel A pin
pinMode(dir, OUTPUT); //Initiates Brake Channel A pin
//Start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
Serial.println("server multi pin button test 1.0"); // so I can keep track of what is loaded
attachInterrupt(1, motor_stop, RISING);
}
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
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println("");
client.println("<HTML><HEAD><TITLE>Projet d'étude : ARDUINO et Contrôle de panneau solaire</TITLE></HEAD>");
client.println("<BODY>");
client.println("<H3>Projet d'étude : ARDUINO et Contrôle de panneau solaire</H3>");
// DIY buttons
client.println("<a href=/?up2 >Monter</a> <a href=/?down3 >Descendre</a> <a href=/?stop4 >STOP</a>");
client.println("</BODY></HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf('2') >0)//checks for 2 MONTER
{
Serial.println("Bouton monter appuyer !!");
digitalWrite(dir, HIGH);
analogWrite(pwm, 255);
delay(3000);
m_stop();
Serial.println("Bouton monter appuyer !! FIN BOUCLE");
}
if(readString.indexOf('3') >0)//checks for 3 DESCENDRE
{
Serial.println("Bouton descendre appuyer !!");
digitalWrite(dir, LOW);
analogWrite(pwm, 255);
}
if(readString.indexOf('4') >0)//checks for 3 STOP
{
Serial.println("Bouton STOP appuyer !!");
m_stop();
Serial.println("Bouton STOP appuyer !! FIN BOUCLE");
}
valswitch = digitalRead(switchhh);
if (valswitch == HIGH)
{
//clearing string for next read
readString="";
}
}
}
}
}}
void motor_stop()
{
Serial.println("motor_stop begin");
m_stop();
Serial.println("motor_stop end");
}
void m_stop()
{
Serial.println("m_stop start");
digitalWrite(pwm, 0);
Serial.println("m_stop end");
}
Many Thanks
please spent some time to get proper layout - CTRL-T does help you
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0E, 0xCE, 0xA1 }; //physical mac address
byte ip[] = {
192, 168, 0, 2 }; // ip in lan
byte gateway[] = {
192, 168, 0, 1 }; // internet access via router
byte subnet[] = {
255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
int switchhh = 2;
int pwm = 5;
int dir = 7;
int valswitch = 0;
void setup()
{
//Setup Channel A from Motor shield
pinMode(pwm, OUTPUT); //Initiates Motor Channel A pin
pinMode(dir, OUTPUT); //Initiates Brake Channel A pin
//Start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
Serial.println("server multi pin button test 1.0"); // so I can keep track of what is loaded
attachInterrupt(1, motor_stop, RISING);
}
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
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println("");
client.println("<HTML><HEAD><TITLE>Projet d'étude : ARDUINO et Contrôle de panneau solaire</TITLE></HEAD>");
client.println("<BODY>");
client.println("<H3>Projet d'étude : ARDUINO et Contrôle de panneau solaire</H3>");
// DIY buttons
client.println("<a href=/?up2 >Monter</a> <a href=/?down3 >Descendre</a> <a href=/?stop4 >STOP</a>");
client.println("</BODY></HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf('2') > 0)//checks for 2 MONTER
{
Serial.println("Bouton monter appuyer !!");
digitalWrite(dir, HIGH);
analogWrite(pwm, 255);
delay(3000);
m_stop();
Serial.println("Bouton monter appuyer !! FIN BOUCLE");
}
if(readString.indexOf('3') > 0)//checks for 3 DESCENDRE
{
Serial.println("Bouton descendre appuyer !!");
digitalWrite(dir, LOW);
analogWrite(pwm, 255);
}
if(readString.indexOf('4') > 0)//checks for 3 STOP
{
Serial.println("Bouton STOP appuyer !!");
m_stop();
Serial.println("Bouton STOP appuyer !! FIN BOUCLE");
}
valswitch = digitalRead(switchhh);
if (valswitch == HIGH)
{
//clearing string for next read
readString="";
}
}
}
}
}
}
void motor_stop()
{
Serial.println("motor_stop begin");
m_stop();
Serial.println("motor_stop end");
}
void m_stop()
{
Serial.println("m_stop start");
digitalWrite(pwm, 0);
Serial.println("m_stop end");
}
and please use only comments when in sync with the code >>> if(readString.indexOf('4') > 0)//checks for 3 STOP
quick code review shows no direct errors. Are you running out of RAM?