Cannot load program onto EtherMega

Combining the power of the ATmega2560 MCU with onboard Ethernet, a microSD card slot, an efficient switchmode power supply, and a small prototyping area. [Product page]
shoots
Posts: 6
Joined: Sun Mar 04, 2012 1:49 am
Location: Fremantle WA

Cannot load program onto EtherMega

Post by shoots » Sun Mar 04, 2012 7:42 am

I have just purchased an EtherMega.
I had been able to download to the device from Vista for a while but when that became impossible (error: Serial port 'com 12' already in use ) I tried on a netbook running Windows 7. This was good for a while, but after coming back to work on it a couple hours later same problem as the other machine. No joy with the XP computor either.

Checked using the PC's hardware manager and nothing else appears to be using the port concerned: it is shown allocated to the Freetronics eleven. I used the driver specified by Freetronics.
An occasional flash issues from the RX LED by the USB socket during attempts to load the new program.
The board is happily flashing away with the last loaded program.

Any suggestions please?

regards,
Peter

User avatar
jonoxer
Freetronics Staff
Freetronics Staff
Posts: 298
Joined: Sat Oct 15, 2011 11:31 am
Location: Melbourne, Australia
Contact:

Re: Cannot load program onto EtherMega

Post by jonoxer » Tue Mar 06, 2012 11:12 am

I haven't seen any follow-up posts so I don't know if this has been sorted out. Are you still having problems with it?

Unfortunately (perhaps!) I don't have a Windows machine myself to test with, but I haven't heard of anyone having that particular problem that I can recall.
--
Jon

shoots
Posts: 6
Joined: Sun Mar 04, 2012 1:49 am
Location: Fremantle WA

Re: Cannot load program onto EtherMega

Post by shoots » Wed Mar 07, 2012 10:14 pm

Thanks Jon,
I suspect the problem may have been that I was using the Serial pins to drive an LCD and this was interfering with the downloading of the program. I have gone to Serial1 and so far no issue. Have yet to try it out on the other computer, but optimistic. It is possible I could load the program without the serial connection to those pins and reconnect, or perhaps the use of (the main) serial also opens another use of the same com port used to load the program. For now though will stay with Serial1 to be sure!

Regards,
Peter

whizz
Posts: 1
Joined: Sat Mar 10, 2012 6:46 pm

Re: Cannot load program onto EtherMega

Post by whizz » Sat Mar 10, 2012 8:07 pm

shoots wrote:Thanks Jon,
I suspect the problem may have been that I was using the Serial pins to drive an LCD and this was interfering with the downloading of the program. I have gone to Serial1 and so far no issue. Have yet to try it out on the other computer, but optimistic. It is possible I could load the program without the serial connection to those pins and reconnect, or perhaps the use of (the main) serial also opens another use of the same com port used to load the program. For now though will stay with Serial1 to be sure!

Regards,
Peter
Not convinced by this, although using the serial for other connections won't help. I have two EMs, which behave very strangely, I'll explain.

The first unit I unpacked, wouldn't even load blink. The green LED just blinked now and again. Dug the second EM out and this loaded blink. However, neither CardInfo or the UDPNTP programs would work.

After trying another laptop, the first was a W7 netbook, the second laptop was a Vista full laptop. I started to put together a long email to the nice guys at FT. Then I changed my mind and did some more tests.

I have come to the conclusion that the USB supply from both laptops were not up to the job. After testing both boards from an XP system with a powerful PSU on the USB hub, everything worked perfectly and the blink, SD and Ethernet tests work perfectly.

Got them working on both laptops only with the hub for uploading. Running A & B from an external PSU allso proved problematic at 9v, better at 10 and OK again at 12v. But without the hub, uploading caused problems and return serial data had dropped characters. If you hammer the Ethernet and the SD then I need at least 12v on the external supply to 'keep up'.

My conclusion is there is not enough 'overhead' available on some USB ports to even drive the board enough to do uploads. I have met this problem with USB port drive abilities and other peripherals in the past.

The quoted PSU range for external supply is higher than quoted even with a 2A supply at 9V, however at 12v and just 500mA drive all is OK.

So at the moment to do 'in the field programming', which would be nice from just netbook, I need a good quality mains powered USB hub. Not good.

I don't have a true *nix box, but from a VM on my laptop, I have the same issue as if I was talking to EM via windows.

So my guess is there is on on board PSU issue with lower voltaged USB ports and the external supply can't go quite as low than about 10v or 11v.

Anyone else got any further experience of this?

shoots
Posts: 6
Joined: Sun Mar 04, 2012 1:49 am
Location: Fremantle WA

Re: Cannot load program onto EtherMega

Post by shoots » Wed Mar 14, 2012 1:16 am

Thanks for the comments Whizz, and the heads up, as down the track I will be using both the ethernet and sd card and also a maths co-processor, LCD, encoder IC and most of the I/O so will have to monitor the power supply situation carefully. It will add up!

So far I have only had it working from the XP computor but later the laptop will have to do its duty.

Peter

cspell
Posts: 2
Joined: Thu Mar 15, 2012 3:25 am

Re: Cannot load program onto EtherMega

Post by cspell » Thu Mar 15, 2012 3:27 am

I just got my new EtherMega today and was just now trying to load a program and had the same problem.

I was not able to upload a program until I plugged in a 9V power supply to the board. Now it's working great.

Thank you for pointing this out.

cspell
Posts: 2
Joined: Thu Mar 15, 2012 3:25 am

Re: Cannot load program onto EtherMega

Post by cspell » Sat Mar 24, 2012 3:41 am

I take it back. This board is a nightmare with Winblows 7. No matter what voltage I feed the board (USB, 9V, 12V) it is a crap shoot getting it to take a download. I have to unplug and plug the usb in to eventually get it to take an upload. I know it's not the program since I'm trying it with the blink program.

What gives?

I never had a single problem with the Eleven board.

I'm very frustrated with the EtherMega.

solidstate
Posts: 1
Joined: Fri Apr 27, 2012 6:36 am

Re: Cannot load program onto EtherMega

Post by solidstate » Fri Apr 27, 2012 6:43 am

I am also having trouble loading a sketch, well i cant load any sketch actually, was working for the first night i had it and now wont load anything. I dont have !!! any where in my code either..i have tried on two different pcs and a mac, all with no luck..can anyone help? Have also tried external power supplies ..

bobj
Posts: 5
Joined: Thu Dec 01, 2011 7:57 pm

Re: Cannot load program onto EtherMega

Post by bobj » Sun Jul 29, 2012 6:22 am

Sorry, but I cannot help either of you, but I have a similar problem......is this an EtherMega issue , or perhaps this is more endemic to the Mega family? Not sure if this is a product issue or a bootloader issue.

I too found the reference to this at. http://www.arduino.cc/cgi-bin/yabb2/YaB ... 1294452951 where the author discovers !!! causes ithe problem (via associated threads) and at the end also mentions \” which appears to be an issue in my case, but it’s not that straight forward....

In my example, if the two lines in the code below (search for zzzz) are BOTH uncommented then the upload hangs on Uploading to I/O board and then hangs the usb/serial port until the EtherMega is reset (using the button). This codes works perfectly on Ethertens.
On EtherMega, If I let in only ONE of those lines, either one, no issue, uploading completes fine. I am using a separate DC supply on the EtherMega, as per your advice on the Freetronics site, but that makes no difference. This issue is repeatable.

Below is the whole code so far. Using IDE 0023. Can’t get my head around changes required for 1.0 so I’ll stick to 0023.

This code I’ve modified from other sources (inc Jons as well) and which has been running since December on a couple of EtherTens without issue, with the commented zzzz lines in service.

The resultant device EtherTen + RTC + SD Card + DHT22 logs temperature and humidity at timed intervals, logs it to the SD card in a filename of the date YYMMDD.csv and also hosts a web page with the current time, date, temperature and humidity and also shows all the log files on the SD card and allows you to open/save the log files via the web interface.

I wanted to extend this and include DHCP or SD card loaded Network configuration, web modifiable IP Address and time/date, but this is currently at the edge of the memory available in the EtherTen, so I bought a EtherMega.....

I’m onto my 2nd EtherMega as I thought the first one had a flaky USB interface.

search for zzzz below (there are two of them) for the lines which cause the issue on EtherMega.

#include <SD.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#include <Ethernet.h>
#include <SPI.h>
#include "DHT.h"

/*
Connections:

RTC
---
5V
SDA to analog 4 EtherTen
SCL to analog 5 EtherTen
SDA to D 20 on EtherMega
SDA to D 21 on EtherMega

DHT22
-----
5V
Grnd
D2 (on Freetronics Etherten)

/*

----------------- 2011 by BobJ--------------------------------------------------------------
Modified from the original barometric pressure sensor code by axel_behrens@web.de
adjusted to suit the Freetronics (http://www.freetronics.com) Etherten + DHT22 Temp/Humidity sensor to write to SD card
also viewable via web browser....as per original implementation
DHT22 has a far simpler read implementation than the original SHT device used
Removed references to SHT and BMP devices.
'Englished' the language (sorry I have no German :( )
Changed SD file content to be truly csv format....e.g. hh,mm,ss,dd,mm,yy,humidity,temperature
-------------------------------------------------------------------------------------------
--------------- original author header and details-----------------------------------------
2011 by Axel Behrens
based on scripts from the included libraries and from
Jonathan Oxer (SHT15)
http://interactive-matter.eu/2009/12/ar ... or-bmp085/ (BMP085)
http://www.ladyada.net/learn/arduino/ethfiles.html (SD/Web)
------------------------------------------------------------------------------------------
*/





/* ----------- DHT22 specific -------*/
#define I2C_ADDRESS 0x68 // required for DHT22
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);

/*---------- ETHERNET ------------*/
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEB, 0xFE, 0xEA };
byte ip[] = {10,19,2,111 }; // set IP adress of Arduino
byte subnet[] = {255,255,255,0};
byte gateway[] = {10,19,2,1};
Server server(80); // set IP port of Arduino

/*---------- SD Card ------------*/
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;


/*---------- variables and constants ------------*/
//const int pause = 1; //SD-Write waiting time
int LedPinSDWrite = 5; //LED for SD write
int LedPinWebserver = 6; //LED for web server


int mth;
int dy;
int yr;
int hr;
char charbufferdy[4];
char charbuffermth[4];
char charbufferyr[7];
char charbufferhr[4];

int sdcounter = 0;
byte oldminute;
byte nowtminute;


// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))

void error_P(const char* str) {
PgmPrint("error: ");
SerialPrintln_P(str);
if (card.errorCode()) {
PgmPrint("SD error: ");
Serial.print(card.errorCode(), HEX);
Serial.print(',');
Serial.println(card.errorData(), HEX);
}
/* ------ commenting out this while statement allows execution even without an SD card present
while(1);
*/
}

void setup() {
Wire.begin();
Serial.begin(9600);
delay(500);
setSyncProvider(RTC.get); // get the time from the RTC
// bmp085_get_cal_data();
// pinMode(5, OUTPUT);
// pinMode(6, OUTPUT);
PgmPrint("Free RAM: ");
Serial.println(FreeRam());

/*---------- SD web server ------------*/
pinMode(10, OUTPUT); // set the SS pin as an output
digitalWrite(10, HIGH); // but turn off the W5100 chip!

if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");

// initialize a FAT volume
if (!volume.init(&card)) error("vol.init failed!");

PgmPrint("Volume is FAT");
Serial.println(volume.fatType(),DEC);
Serial.println();

if (!root.openRoot(&volume)) error("openRoot failed");

// list file in root with date and size
PgmPrintln("Files found in root:");
root.ls(LS_DATE | LS_SIZE);
Serial.println();

// Recursive list of all directories
PgmPrintln("Files found in all dirs:");
root.ls(LS_R);

Serial.println();
PgmPrintln("Done");

/*---------- web server start ------------*/
// Ethernet.begin(mac, ip);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
oldminute = minute();
}

#define BUFSIZ 100

void loop()
{

float h = dht.readHumidity();
float t = dht.readTemperature();

Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(" Now ");
digitalClockDisplay(); // get time from RTC

// Serial.println(nowtminute, DEC);
// Serial.print("Old ");
// Serial.println(oldminute, DEC);


mth = month(); // convert byte to int

itoa(mth,charbuffermth,10); // convert int to string
// if (month() < 10) strcat("0", charbuffermth);
Serial.println(charbuffermth);

dy = day(); // convert byte to int
itoa(dy,charbufferdy,10); // convert int to string

yr = year(); // convert byte to int
itoa(yr,charbufferyr,10); // convert int to string

hr = hour(); // convert byte to int
itoa(hr,charbufferhr,10); // convert int to string


delay(1000);
nowtminute = minute();
// check if 10 mins are over for writing data onto SD every 10 mins
if (nowtminute == oldminute +1) {
// changed line above from +10 to +1 for testing.......bobj

/*---------- execute this part every 10 mins ------------*/
digitalWrite(6, HIGH);
delay(5000);
digitalWrite(6, LOW);
oldminute = nowtminute;

/*---------- turn off web server for writing the SD ------------*/

pinMode(10, OUTPUT);
digitalWrite(10, HIGH);

file.writeError = false; // clear write error
card.init(SPI_HALF_SPEED, 4); // initialize the SD card at SPI_HALF_SPEED
volume.init(&card); // initialize a FAT volume
root.openRoot(&volume); // open the root directory

/*---------- combining the filename ------------*/
//start of concatenated YYYYMMDD.csv filename.
char name[10] ="";
strcat(name, charbufferyr);
strcat(name, charbuffermth);
strcat(name, charbufferdy);
strcat(name, ".csv"); //append the file ending
// Serial.print(name);
PgmPrint("Appending to: ");
Serial.println(name);
delay(1000);

/*---------- writing the data to SD ------------*/
file.open(&root, name, O_CREAT | O_APPEND | O_WRITE);
SDdigitalClockDisplay();
file.print(h);
file.print(",");
file.print(t);
file.print(",");
file.println();
file.close();

// blink the LED for writing SD
// digitalWrite(6, HIGH);
//delay(200);
// digitalWrite(6, LOW);
// delay(200);
// digitalWrite(6, HIGH);
// delay(200);
// digitalWrite(6, LOW);

Serial.print('.');
Serial.println();
Serial.println("Done SD Writing");
delay(1000);
digitalWrite(10, LOW);

/*---------- END OF execute this part every 10 mins ------------*/
}


/*---------- webserver part ------------*/
char clientline[BUFSIZ];
int index = 0;

Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;

// reset the input buffer
index = 0;

while (client.connected()) {
if (client.available()) {
char c = client.read();

// If it isn't a new line, add the character to the buffer
if (c != '\n' && c != '\r') {
clientline[index] = c;
index++;
// are we too big for the buffer? start tossing out data
if (index >= BUFSIZ)
index = BUFSIZ -1;

// continue to read more data!
continue;
}

// got a \n or \r new line, which means the string is done
clientline[index] = 0;

// Print it out for debugging
Serial.println(clientline);

// Look for substring such as a request to get the root file
if (strstr(clientline, "GET / ") != 0) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();

// print all the files, use a helper to keep it clean and print actual sensor data and time
client.println("<h1>Remote Temperature & Humidity Logger</h1>");
client.print("Adapted from Axel Behrens (and others) original code by BobJ - ver 20111230d F/W. Ver Prototype0.7a H/W");
client.print("<h3>Current Temperature: </h3>"); client.print(t); client.print(" degrees C");
client.print("<h3>Current Humidity: </h3>"); client.print(h); client.println(" %");
client.print("<h3>Current Local Time: </h3>");
client.println("<h3> </h3>");
if (hour() < 10) client.print('0');
client.print(hour()); client.print(":");
if (minute() < 10) client.print('0');
client.print(minute()); client.print(":");
if (second() < 10) client.print('0');
client.print(second());
client.print(" ");
client.print(day()); client.print("/");
client.print(month()); client.print("/");
client.print(year());
client.println();
client.println("<h3>Files on MicroSD Card:</h3>");
ListFiles(client, LS_SIZE);
}
else if (strstr(clientline, "GET /") != 0) {
// this time no space after the /, so a sub-file!
char *filename;

filename = clientline + 5; // look after the "GET /" (5 chars)
// a little trick, look for the " HTTP/1.1" string and
// turn the first character of the substring into a 0 to clear it out.
(strstr(clientline, " HTTP"))[0] = 0;

// print the file we want
Serial.println(filename);

if (! file.open(&root, filename, O_READ)) {
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("<h2>File Not Found!</h2>");
break;
}

Serial.println("Opened!");

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/plain");
client.println();

int16_t c;
while ((c = file.read()) > 0) {
// uncomment the serial to debug (slow!)
//Serial.print((char)c);
client.print((char)c);
}
file.close();
}
else {
// everything else is a 404
client.println("HTTP/1.1 404 Not Found");
client.println("Content-Type: text/html");
client.println();
client.println("<h2>File Not Found!</h2>");
}
break;
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
} // end of if cycle
digitalWrite(5, HIGH);
delay(5000);
digitalWrite(5, LOW);
delay(1000);


/*---------- reset the old minute, otherwise dead end cycle possible ------------*/
if (oldminute == 59) {
oldminute = 0;
} if (oldminute == 58) {
oldminute = 0;
} if (oldminute == 58) {
oldminute = 0;
} if (oldminute == 57) {
oldminute = 0;
} if (oldminute == 56) {
oldminute = 0;
} if (oldminute == 55) {
oldminute = 0;
} if (oldminute == 55) {
oldminute = 0;
} if (oldminute == 54) {
oldminute = 0;
} if (oldminute == 53) {
oldminute = 0;
} if (oldminute == 52) {
oldminute = 0;
} if (oldminute == 51) {
oldminute = 0;
} if (oldminute == 50) {
oldminute = 0;
} if (oldminute == 49) {
oldminute = 0;
}

}


void ListFiles(Client client, uint8_t flags) {
// This code is just copied from SdFile.cpp in the SDFat library
// and tweaked to print to the client output in html!
dir_t p;

root.rewind();
client.println("<ul>");
while (root.readDir(p) > 0) {
// done if past last used entry
if (p.name[0] == DIR_NAME_FREE) break;

// skip deleted entry and entries for . and ..
if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;

// only list subdirectories and files
if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;

// print any indent spaces
// zzzz client.print("<li><a href=\"");

for (uint8_t i = 0; i < 11; i++) {
if (p.name == ' ') continue;
if (i == 8) {
client.print('.');
}
client.print(p.name);
}
// zzzz client.print("\">");


// print file name with possible blank fill
for (uint8_t i = 0; i < 11; i++) {
if (p.name == ' ') continue;
if (i == 8) {
client.print('.');
}
client.print(p.name);
}

client.print("</a>");

if (DIR_IS_SUBDIR(&p)) {
client.print('/');
}

// print modify date/time if requested
if (flags & LS_DATE) {
root.printFatDate(p.lastWriteDate);
client.print(' ');
root.printFatTime(p.lastWriteTime);
}
// print size if requested
if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
client.print(' ');
client.print(p.fileSize);
}
client.println("</li>");
}
client.println("</ul>");
}

/*---------- writing time to serial ------------*/
void digitalClockDisplay(){
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}

/*---------- writing time to serial incl. preceding colon and leading 0 ------------*/
void printDigits(int digits){

Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}

/*---------- writing time to SD file ------------*/
void SDdigitalClockDisplay(){
file.print(hour());
SDprintDigits(minute());
SDprintDigits(second());
file.print(",");
file.print(day());
file.print(",");
file.print(month());
file.print(",");
file.print(year());
file.print(",");
}


/*---------- writing time to SD incl. preceding colon and leading 0 ------------*/
void SDprintDigits(int digits){
file.print(",");
if(digits < 10)
file.print('0');
file.print(digits);
}

void strcat(char* original, char appended)
{
while (*original++)
;
*original++ = appended;
if (appended)
*original = '\0';
}

================================================================================================

User avatar
jonoxer
Freetronics Staff
Freetronics Staff
Posts: 298
Joined: Sat Oct 15, 2011 11:31 am
Location: Melbourne, Australia
Contact:

Re: Cannot load program onto EtherMega

Post by jonoxer » Thu Aug 30, 2012 8:05 am

Hey everyone, sorry about the absence.

It sounds to me like there may be a couple of different problems behind the symptoms mentioned in this thread. The early posts seem to be mostly power-related, so one thing worth trying is to use a different USB cable. It's possible that in the case of the EM that won't work plugged into a laptop but will work plugged into a hub, it's right on the borderline of the voltage drop on the USB cable causing problems.

For those having power issues, could you please try measuring the voltage on the 5V rail in both failing and working conditions, and see if it's low when failing?

Regarding @bobj's issue, I think that's unrelated to power. Perhaps try wrapping the link target in single quotes, instead of double-quotes? I don't really have any good suggestions for that one.
--
Jon

Post Reply