Nothing happening over serial (everything else okay!)

A shrunk down Leonardo-compatible board, thumb drive sized with native USB support. [Product info]
Post Reply
mafro
Posts: 4
Joined: Fri Oct 05, 2012 11:19 pm

Nothing happening over serial (everything else okay!)

Post by mafro » Wed May 15, 2013 9:31 am

Hey forums, I'm on OSX and I've had an easy time getting most of everything working - with the conspicuous exception of the Serial USB.. My Leostick is has the bootloader v1.

My Leostick appears happily at:

Code: Select all

/dev/tty.usbmodemfa131
I've wired in a simple switch as shown in this tutorial: http://arduino.cc/en/Tutorial/InputPullupSerial.

The following code was adapted from the tutorial and correctly flicks the LED on when I press the button. I just don't see anything in the serial monitor.

Code: Select all

int pushButton = 2;
int led = 13;

void setup(){
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  pinMode(pushButton, INPUT);
  digitalWrite(pushButton, HIGH);
  pinMode(led, OUTPUT); 
}

void loop(){
  int sensorVal = digitalRead(pushButton);
  Serial.println(sensorVal);
  // write the inverted switch value to the LED
  digitalWrite(led, !sensorVal);
}
I've tried both the Arduino IDE Serial Monitor and the following code I knocked up in Python. In no case can I get any output on the serial over USB.

Python code:

Code: Select all

#! /usr/bin/env python

import serial
from time import sleep

port = "/dev/tty.usbmodemfa131"
ser = serial.Serial(port, 115200, timeout=0)
ser.setRTS(True)
ser.setDTR(True)

running = True

while running:
    try:
        data = ser.readline()
        if len(data) > 0:
            print 'Got:', data

        sleep(0.5)
        print 'not blocked'

    except KeyboardInterrupt:
        running = False

ser.close()

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Nothing happening over serial (everything else okay!)

Post by angusgr » Thu May 16, 2013 2:28 am

Hi mafro,

Sorry to hear it's not working for you.

Are you using the latest board profile (3.3)? Do you have "Freetronics LeoStick V1" set under Tools -> Board in the Arduino IDE?

I tried the sketch on my V1 and it worked, but it only compiled after I removed this section:

Code: Select all

while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
... this Leonardo feature is not part of the Leonardo Beta release, that the V1 is based on. It works in the V2, or if you update the V1 to V2.

The fact you're not getting an error from it makes me think you're using the LeoStick V2 profile or the Leonardo profile, which would be the root cause of the problem.

The sketch should work fine with it removed though (you just might miss some very early serial messages that are sent before OS X is ready to receive them, if you're worried about that then replace that section with a line saying

Code: Select all

delay(500);
Please let us know you get on.

- Angus

mafro
Posts: 4
Joined: Fri Oct 05, 2012 11:19 pm

Re: Nothing happening over serial (everything else okay!)

Post by mafro » Thu May 16, 2013 4:40 am

Hi Angus, thanks for the reply.

I added the hacky bit of code you removed and switched to the Leonardo profile only as a last resort. It's good to know that that definitely won't work :)

Anyway, I have resolved my problem - but purely by chance.. Today I received a powered USB hub through the post (too many Pis and Arduinos to plug into my poor Macbook), and running through that, the Serial output works as expected. Switching back to the USB port in the side of the Macbook, no dice.

Any ideas on why that might be? A power issue seems unlikely.

Cheers
Matt

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: Nothing happening over serial (everything else okay!)

Post by angusgr » Thu May 16, 2013 5:15 am

Hi Matt,

Glad to hear you got it working. That is indeed very odd, the fact that it's successfully enumerating as a USB serial device should rule out most low-level hardware or signalling problems. However the fix points directly to something like that.

I'm not familiar with how OS X numbers serial ports, but is it possible the changing port address (due to different port arrangement) changed the name and somehow stopped some other piece of software that was holding the serial port open and prevented you from seeing any output from it?

- Angus

mafro
Posts: 4
Joined: Fri Oct 05, 2012 11:19 pm

Re: Nothing happening over serial (everything else okay!)

Post by mafro » Thu May 16, 2013 5:24 am

Yeah it seems like that's the case. Now you mention it, I've previously noted that particular port can be temperamental when attaching a USB keyboard - a bit of a plug/unplug nonsense eventually gets it working. I expect this is the same problem.

Good to know Apple hardware is to blame!

Cheers
Matt

Post Reply