Teensy 2.0 and WGM-301 USB-connect GPS

Status
Not open for further replies.

insane

Active member
Never thought this was going to be so hard.

1. So, I've got a USB<>RS232 converter connected to pins 7 & 8 on the Teensy (plus pwr and gnd); the converter uses the SiLabs CP2102 chip set. Tested the setup using the UART example code from PJRC website: UART_USB_Dual_Serial. Works as expected.

Code:
// This line defines a "Uart" object to access the serial port
// usage notes: http://pjrc.com/teensy/td_uart.html

HardwareSerial Uart = HardwareSerial();

void setup() {
	Serial.begin( 4800 );
        Uart.begin( 115200 );
        pinMode(PIN_D6, OUTPUT);
}

void loop() {
        int incomingByte;
        
	if (Serial.available() > 0) {
		incomingByte = Serial.read();
		Serial.print("USB received: ");
		Serial.println(incomingByte, HEX);
                Uart.print("USB received:");
                Uart.println(incomingByte, HEX);
		//Uart.write( incomingByte );
	}
	if (Uart.available() > 0) {
		incomingByte = Uart.read();
		Serial.print("UART received: ");
		Serial.println(incomingByte, HEX);
                Uart.print("UART received:");
                Uart.println(incomingByte, HEX);
	}
}

2. I've got a decent, integrated 1Hz GPS with a USB connector on it. If I plug it into my PC and open a com port, GPS data just comes over--once-per-second--onto the screen of my ascii terminal session.

TermiteImage.jpg

...all seems good, so far.

3. Plug the USB connector from the GPS into the USB connector of the USB<>RS232 converter with a F/F USB adapter in the middle, and loaded the following code on the Teensy (basically adapted from Mikal Hart's example):

Code:
// Documentation: https://www.pjrc.com/teensy/td_libs_TinyGPS.html

/* On Teensy, the UART (real serial port) is always best to use.     */
/* Unlike Arduino, there's no need to use NewSoftSerial because      */
/* the "Serial" object uses the USB port, leaving the UART free.     */
HardwareSerial Uart = HardwareSerial();

void setup() {
  Serial.begin(115200);
  Uart.begin(4800);

  delay(1000);
  Serial.print("Testing TinyGPS library v. ");
  Serial.println("by Mikal Hart");
  Serial.println();
}

void loop() {
  unsigned long start = millis();

  // Every 5 seconds we print an update
  while (millis() - start < 5000) {
    if (Uart.available()) {
      char c = Uart.read();
       Serial.print(c);  // uncomment to see raw GPS data
    }
  }
}

...but there is no output. I suspect is has something to do with no USB host--but then, I think all that stuff is just magic, anyway. Any ideas?
 
Yes, you have two USB slave devices and no USB host. So you have connected everything together at the physical level, but nothing is talking to the two USB devices.

USB host shields for Arduino do exist, and there is also a USB host adapter for the Arduino Pro Mini (the form factor is more suited to the Teensy than the hulking big Arduino shields). Then you need to look into the USB host library, which is sparsely commented, has few examples and almost no documentation (last I looked). But it can be done.

It would probably be significantly easier to use a serial output GPS (for example this one) rather than diving into the arcane mysteries of the USB host.
 
Status
Not open for further replies.
Back
Top