I have been working on an ROV that uses a Nano + ENC28j60 to send telemetry data back to the control station via a WiFi radio. The Ethernet from the Nano and the Ethernet from an HD camera are combined by a switch (Ethernet Switch Module - 3 Port 10/100M) and then sent to the radio. All are static IP addresses.
When I start the full system from a power-up, the Nano does NOT initialize properly and does not send the telemetry data.
When I connect the radio directly to the Nano, it starts and sends data properly. After it has started, I can connect both the Nano and radio to the switch and it continues to operate properly until the next power-down.
This (to me) seems to indicate that the Nano's Ethernet needs to negotiate some type of protocol (or something similar) that it isn't able to do through the switch but CAN do through the radio.
Has anyone run into this? How did you resolve the issue????
/*
* Convert to UDP Ethernet 06/02/2017
Telemetry Transmit with 10DOF Sensors
*/
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_BMP085_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_10DOF.h>
#include <UIPEthernet.h>
EthernetUDP udp;
// Assign a unique ID to the sensors
Adafruit_10DOF dof = Adafruit_10DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
//Define soft variables
int compass = 0 ; // Compass in degrees, default 0 degrees
int pressure = 600 ; // Pressure in Pascals,
int pitch = 0 ; // pitch in degrees
int checksum = 0 ;
int len ;
int numBytes ;
int sendFlag ;
// Timing
int tick = 0 ; // 1 Second clock
unsigned long currentT = 0 ;
unsigned long lastT = 0 ;
struct DOFDATA
{
uint16_t compass;
uint16_t pressure;
uint16_t pitch;
};
float heading ;
//************** SETUP ***********************
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
uint8_t mac[6] = {0x11,0x22,0x33,0x04,0x05,0x06};
Ethernet.begin(mac,IPAddress(10,0,199,5));
/*
// Initialise the sensors
Serial.println("initialize sensors");
if(!accel.begin())
{
// There was a problem detecting the LSM303 ... check your connections
Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
while(1);
}
if(!mag.begin())
{
// There was a problem detecting the LSM303 ... check your connections
Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
while(1);
}
Serial.println("initialized mag");
if(!bmp.begin())
{
// There was a problem detecting the BMP180 ... check your connections
Serial.println("Ooops, no BMP180 detected ... Check your wiring!");
while(1);
}
Serial.println("initialize bmp");
Serial.println("Tx Started here");
*/
Serial.println("Setup Complete");
}
//************** LOOP ***********************
void loop() {
// 1 Second timer loop
(currentT = (millis()/1000)) ;
if (currentT > lastT) {
(lastT = currentT ) ;
tick++ ;
}
if (tick >= 6) {
(tick = 0) ;
}
switch(tick){
case 3: {
upData () ; // update data
// sensorRead() ; // read sensors - SKIP fror now
tick++ ;
break ;
}
case 5: {
sendData () ; //transmit data
tick++ ;
break ;
}
}
}
// *********************** Sensor Reads *****************
void sensorRead()
{
sensors_event_t accel_event;
sensors_event_t mag_event;
sensors_event_t bmp_event;
sensors_vec_t orientation;
// Calculate pitch and roll from the raw accelerometer data
accel.getEvent(&accel_event);
if (dof.accelGetOrientation(&accel_event, &orientation))
{
// 'orientation' should have valid .roll and .pitch fields
(pitch =(orientation.pitch));
// Get a new sensor event
sensors_event_t event;
bmp.getEvent(&event);
// Display the results (barometric pressure is measure in hPa)
if (event.pressure)
{
// Display atmospheric pressure in hPa
(pressure = (event.pressure));
}
else
{
Serial.println("Sensor error");
}
}
// Calculate the heading using the magnetometer
mag.getEvent(&mag_event);
if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
{
// 'orientation' should have valid .heading data now
(compass = (orientation.heading));
}
return ;
}
// ******************* DATA SEND ****************
void sendData (){
// data to send
DOFDATA dd;
dd.compass = compass ; // 0 to 359 degrees, 0 to 168$
dd.pressure = pressure ; // to 1200 "H2O, 0 to 4B0$
dd.pitch = pitch ; // -20 to +20 Degrees, ffec to 14$
udp.beginPacket(IPAddress(10,0,199,6),5000);
int numBytes = udp.write((byte*)&dd, sizeof(dd));
sendFlag = udp.endPacket();
// if (sendFlag != 0 ) ;
Serial.print("Send Flag ") ;
Serial.println (sendFlag);
Serial.print ("Number of Bytes ") ;
Serial.println (numBytes) ;
Serial.print ("Heading ") ;
Serial.println (compass) ;
Serial.print ("Pressure ") ;
Serial.println (pressure) ;
Serial.print ("Pitch ") ;
Serial.println (pitch) ;
Serial.println (" ");
}
// ************************************************
void upData (){
// inc. fudged data values
compass=(compass+10) ; // inc. compass 0 to 359 degrees, 0 to 168$
if (compass>360) {
compass=0 ;
}
pressure = (pressure +10) ; // inc pressure // 0 to 1200 "H2O, 0 to 4B0$
if (pressure>1200) {
pressure = 0 ;
}
pitch++ ; // inc pitch // -20 to +20 Degrees, ffec to 14$
if (pitch>20) {
pitch= (-20) ;
}
return ;
}