Articles Hierarchy

Articles Home » Arduino Projects » arduino debug

arduino debug

many questions about arduino debug, but well, there is only the idea to use many prints.
now: that can be improved by this idea from 4um using it as a macro with a compiler switch to disable it.
and add i try to combine it with my style using a menu variable to toggle this diagnostic prints by menu.
In this example i just use the basics of my menu project to test it. And also build it into the menu system, pls download V2.5 from here

but if you want put in some money, this might be close to real debugging. if i ever test / buy it, i will report about it here.

some nice ideas here i found also in 4um
there is mentioned the gdb ?? need more digging

the tools from NICK look cool, but are pre IDE1.0.0 and not run anymore.
still i want play I2C and start from the basics, also find this.
now if you play with 2 arduino i was used to connect one by HTERM and see serial data,
but i use a arduino micro pro as slave / debugger and not see anything. ( on the Master, a arduino MEGA, the HTERM works )
so i started with 2 different IDEs so i can adjust 2 com ports and have 2 terminal windows open.

and make a string version for this
// call dbgs(" a "+String(a)+" f "+String(f));
void dbgs(String debugstring) {
Wire.beginTransmission(WIRESLAVE); // transmit to device
int bytes = debugstring.length();
for ( int n = 0; n < bytes; n++) { Wire.write(debugstring.charAt(n)); }
Wire.endTransmission(); // stop transmitting that makes a linefeed at slave


on NICKs page you see 2 arduino UNO wired with 4 wires,
A4 (SDA), A5 (SCL), 5V and GND
now, if the job of the Slave is to catch debug messages from the Master and print them to a terminal window
the Save will be connected to a PC ( by USB ) so 5V is there.
and we need the Slave because the Master is connected to PC and doing data exchange ( USB ) what we don't want to disturb by the diagnostic outprints. so also the Master is connected to ?same? PC and there might not even a GND wire be required.
As i run with 2 wires ( 10cm) only it works. Hmm the length of that multimaster multidrop I2C link is given with 1m / 400 pF
( and using pullups 10kohm to V5 on both lines )
using a GND wire between the 2 arduinos makes my link 10cm short but creates a ground loop via the 2 USB cables, and loops are always a sink for induction;
without the ground wire the link uses the USB ground in a kind of star configuration with unknown length and capacity;
actually with AND without the ground wire this 5V ( TTL ) signal level is weak and needs to be checked, for connection 5V and 3V3 arduinos need bidirectional level shifters.
For longer bus cables ( like 20m ) need I2C-bus extender, they try to change the serial TTL Volt signal to a 10 times higher current. That remembers RS232 to RS422.
UNO: A4 (SDA), A5 (SCL),
MICRO PRO: (2) (SDA), (3) (SCL),
Leonardo: SDA, SCL,
DUE D20 (SDA), D21 (SCL), 1k5 pullup to 3V3!

now for a debug there might be a need of a condition, here for test i use a compare of the "a" value,
but when that is a INTeger there will be a rollover every 3 sec ( if no wait, no other serial I/O is used ).
now i define it as a unsigned LONG:
unsigned long a = 0;
unsigned long startT;
and in startup:
startT = millis();
and the debug condition as
if (a == 100000UL) { dbgs("t: "+String(millis()-startT)+" a: "+String(a)+" f: "+String(f)); }
pls note the 100000UL notation, and in debug i see:
t: 4698 a: 100000 f: 31830.988000
after 5 sec and i not wait for the rollover

there are 2 thing i noticed,
1- the start up is a problem, looks like when i power up both,
- - the arduino UNO with the menu program / debug by I2C
- - and the arduino micro pro with the I2C catch and print program
i can not get a stabil communication, means i see the Start WIRE as slave device 44
but nothing else. so at first i changed the menu program that it sends also at boot a msg. "boot" via I2C.
now, when i reconnect the USB ( and with this the power ) of the menu program ( arduino UNO ) see that boot and the 1.000.000 loop time
days: 0 time: 0 : 0 : 21
days: 0 time: 0 : 0 : 43
days: 0 time: 0 : 1 : 5

when i start the terminal for that USB it ( the boot ) happens again, ( we know, for the UNO, not the Leonardo )
2 - and something what surprises me and i bet most of you too:
when i close that arduino terminal window i see in the debug terminal window that the UNO boots again!!!
now that is news and i never see / think about that, how could i.

oh yes, as i not give up so easy, test the HTERM again on the arduino MICRO PRO and after i pressed the input control DTR button see
Start WIRE as slave device 44 ( thats the boot msg from I2Cslave MICRO PRO and then the debug lines from UNO also come.
days: 0 time: 0 : 18 : 28
days: 0 time: 0 : 18 : 50

but not the boot and first loopreport time info from UNO.
i play some more and see following, using the connect and disconnect button OR shut down HTERM program and restart,
for a connection to a UNO i see following:
if DTR is not pressed
there is no boot from UNO ( thats why i preferred that program to the arduino terminal )
if DTR is pressed
UNO reboots every time ( like with the arduino terminal )
for the micro pro / Leonardo,
if DTR is not pressed
i see NO boot and NO DATA
if DTR is pressed
i see NO boot but DATA
see more here

its not related to debugging, but as i just learn little bit about I2C
i play with the RTC chip again, pls see here