I am working on a control panel for a monitor, using a arduino mega with a ethernet shield, the monitor is tcp commands are attached I have the program working , its basically the arduino attached to a rotary switch and sending out tcp commands depending on the position iof the switch, so I am using input_pullups and polling for lows, but it works fine when hook up to the usb port as soon as i go on the 9v power supply it just goes crazy sending comands at random almost like the boards ground is floating, is i remove the ground pin connected to the board and touch it with the outside of the usb plug it works again,
#include <SPI.h>
#include <Ethernet.h>
// mac adress (made up number)
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x9E, 0x16 };
// Static IP for arduino
byte ip[] = { 192,168,0,222 };
// Static IP for Smartview
byte bmip[] = { 192,168,0,2 };
// Client Ethernet
EthernetClient clientSmartView;
// not needed
String code;
int i;
/**** one time running code ****/
void setup() {
//pin setup
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
pinMode(32, INPUT_PULLUP);
pinMode(13, OUTPUT);
// serial connection for troubleshoot
Serial.begin(9600);
Serial.println("Serial connection established");
delay(500);
Serial.println("Port set at 9600 bps");
delay(500);
// Connection Ethernet
Ethernet.begin(mac,ip);
delay(500);
Serial.println("IP connection in progress ...");
delay(1000);
//if connected say so otherwise say failed
if(clientSmartView.connect(bmip, 9992 )) {
Serial.println("connection established");
}
else {
Serial.println("Connection failed");
}
}
//main progran loop
void loop(){
//pin declare
int sensorVal1 = digitalRead(30);
int sensorVal2 = digitalRead(31);
int sensorVal3 = digitalRead(32);
if (sensorVal1 != HIGH && i != 6) {
delay(100);
//Serial.println("pin 30");
//Serial.println(i);
MONAPIC();
//int i = 6;
}
if (sensorVal2 != HIGH && i != 7) {
delay(100);
//Serial.println("pin 31");
//Serial.println(i);
MONAVEC();
// int i = 7;
}
if (sensorVal3 != HIGH && i != 8) {
delay(100);
//Serial.println("pin 32");
//Serial.println(i);
MONAWAV();
// int i = 8;
}
}
//subroutines
int MONAPIC()//monitor A picture
{
clientSmartView.connect(bmip, 9992);
delay(100);
if (clientSmartView.connected()) {
clientSmartView.println("MONITOR A: ");
clientSmartView.println("ScopeMode: Picture");
clientSmartView.write(0x0A);
clientSmartView.stop();
i=6;
}
return i;
}
int MONAVEC()//monitor A vector
{
clientSmartView.connect(bmip, 9992);
delay(100);
if (clientSmartView.connected()) {
clientSmartView.println("MONITOR A: ");
clientSmartView.println("ScopeMode: Vector100");
clientSmartView.write(0x0A);
clientSmartView.stop();
i=7;
}
return i;
}
int MONAWAV()//monitor A waveform
{
clientSmartView.connect(bmip, 9992);
delay(100);
if (clientSmartView.connected()) {
clientSmartView.println("MONITOR A: ");
clientSmartView.println("ScopeMode: WaveformLuma");
clientSmartView.write(0x0A);
clientSmartView.stop();
i=8;
}
return i;
}
SmartView Manual.pdf (2.78 MB)