Use The Terminal To Test Arduino Is Working

Hi all...

(Apologies for any typos at all.)

This is a step by step _script_ to check if your Arduino is talking to your Linux or Macbook Pro computer using the Terminal...

It works on at least 3 Linux flavours and now the Macbook Pro...

I hope you find it useful as a simple check for your Arduino setup...

This is issued as Public Domain.

The "Test.pde" is the code to program the Arduino with.
My Arduino programming SW is old and I am aware that the "Test.pde" script will not compile on current Arduino programming SW. I am assuming you will know what to do with it...

A basic, terminal, test sequence to check that the Arduino Diecimila board is _talking_ to your computer.

Step by step testing inside a Linux , OR, Macbook Pro Terminal usage for the USB Arduino Diecimila Board...
Issued as completely Public Domain by B.Walker, G0LCU, 2011-2013.

Common to both systems:-
------------------------

1) Boot up to your Linux flavour or Macbook Pro as root, (or run in a root Terminal).
2) Temporarily disable any net access or use a stand-alone machine.
3) Plug in the USB Arduino board.
4) Open up a, (root), Terminal and clear the screen.
5) clear<RETURN/ENTER>

Linux flavours first:-
----------------------
6) Check that you have a device as ttyUSB?
IMPORTANT NOTE: Arduino boards are now detected as ttyACM? so although NOT tested this might still work...
If this is the case then replace ttyUSB? with ttyACM? below...

7) ls /dev<RETURN/ENTER>
NOTE:- ? above will probably be 0.
8) If ttyUSB0, (to 7), appears then carry on; otherwise ignore the remainder of this text.

NOTE:- Assuming the device is ttyUSB0 from now on, change below if needed to your ttyUSBx device.
9) Place a wire link between ANALOG 0 and the 3.3 V terminals, OR,
A potentiometer wired, one end to ground, GND, the other end to +5V and the wiper to ANALOG 0...

NOTE:- 'chmod' is probably not really needed but added for fullness!
10) chmod 666 /dev/ttyUSB0<RETURN/ENTER>

11) Set up the on board serial I/O to 9600bps and RAW data transfer for PCLinuxOS and Debian.
12) stty -F /dev/ttyUSB0 9600<RETURN/ENTER>
13) stty -F /dev/ttyUSB0 raw<RETURN/ENTER>

14) Now start printing characters to the screen...
15) cat < /dev/ttyUSB0<RETURN/ENTER>
NOTE:- The wire link characters will be from about 168 to 174 decimal allowing for bit error of the Arduino ADC.

16) Remove and replace the wire link from ANALOG 0 and GND or ANALOG 0 and 5 V too, OR,
A potentiometer wired, one end to ground, GND, the other end to +5V and the wiper to ANALOG 0...
17) Press 'Ctrl-C' to stop any characters being printed to the Terminal.
18) Unplug the USB Arduino board.
19) Power down the computer IF REQUIRED.

Now the Macbook Pro:-
---------------------
6) Now find the device name, mine is tty.usbserial-A7007cvs, yours will probably be much different...

7) ls /dev<RTETURN/ENTER>
8) If you have a new tty* note its name then carry on, otherwise ignore the rest of this text.
(I will use my device name for this example.)

9) Place a wire link between ANALOG 0 and the 3.3 V terminals, OR,
A potentiometer wired, one end to ground, GND, the other end to +5V and the wiper to ANALOG 0...

NOTE:- 'chmod' is probably not really needed but added for fullness!
10) chmod 666 /dev/tty.usbserial-A7007cvs<RETURN/ENTER>

11) Now start printing characters to the screen...
(The command stty does NOT work for this on the Macnook Pro so revert to the command cu instead.)
12) cu -l /dev/tty.usbserial-A7007cvs -s 9600<RETURN/ENTER>

13) Ctrl-C does not work so just close down the Terminal COMPLETELY.
14) Unplug tha Arduino board.
15) Power down the computer IF REQUIRED.

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

This is the "test.pde" code for the Arduino Diecimila board:-
-------------------------------------------------------------

/* Test.pde */
/* Using the Arduino as a DEMO single channel ADC for WinUAE. */
/* For use with AF2005 or greater. This is just demonstration code */
/* only and shows that I/O is possible through WinUAE by other means. */

/* Set up a variable 1 byte in size for basic analogue input. */
int analogue0 = 0;

void setup() {
  /* open the serial port at 9600 bps. This rate is used for purely */
  /* for simplicity only. */
  Serial.begin(9600);

  /* Set the analogue voltage reference, DEFAULT is 5V in this case. */
  analogReference(DEFAULT);
}

void loop() {
  /* Read the 10 bit analogue voltage on analogue input 0. */
  analogue0 = analogRead(0);
  /* Convert to a byte value by dividing by 4. */
  analogue0 = analogue0/4;

  /* Send to the Serial Port the byte value. */
  Serial.print(analogue0, BYTE);
  
  /* Delay 500 milliseconds before taking the next reading. */
  delay(500);
}

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

Enjoy finding simple solutions to often very difficult problems...

Bazza, G0LCU...
1 Like