chipKIT® Development Platform

Inspired by Arduino™

MPIDE Serial Communication Issue

Created Tue, 06 Nov 2012 04:30:51 +0000 by newtothesethings


newtothesethings

Tue, 06 Nov 2012 04:30:51 +0000

Hi,

I am new to the world of microcontrollers, and I am experiencing a problem. My issue is that I cannot seem to communicate with my board using MPIDE through the serial connection the way I would like to. For example, I cannot get the following simple “Hello World” code to successfully print a message to my serial monitor.

void setup(){
  Serial.begin(9600);           
  Serial.println("Hello world!");  
}

void loop(){
}

I am using the ChipKIT Max32 with a shield. I’m running Windows 7 64-bit with MPIDE (I have tried the 20120903 version and the 20111221 version both for windows). Later I plan on using Processing for a GUI.

I have attempted to resolve this problem in many ways, and have done a lot of troubleshooting. Here is what I know:

  1. I can run the Blink example under File -> Examples -> Basics-> Blink. This works perfectly which tells me that I have everything hooked up correctly.
  2. I cannot run the Dimmer example under File -> Examples -> Communication -> Dimmer. It does not work whether I try and use Processing, or if I try to send inputs directly from the serial monitor.
  3. My baud rate is set to 9600 for both the serial monitor and in my code. (Although I have tried others)
  4. I am using the chipKIT MAX32-USB for Serial option in MPIDE
  5. When I upload my code, the two LEDs blink rapidly as I would expect. If I send a value from the serial port monitor, one of the LEDs blinks once.
  6. Even if I put print statements in the loop, I get nothing. This makes me think it isn’t a timing issue.

Overall, I am running out of things to try. I feel that I have read every forum post related to serial communications already. My last effort may be to cut the automatic reset action on the board by slicing the trace between the pins of JP5. This idea came to me from a similar problem someone was having with a different board.

Any suggestions are appreciated. Thank you.


BloodyCactus

Tue, 06 Nov 2012 19:12:04 +0000

put a delay(5000) in after you open the serial port in the sketch.

you need to open the serial window in MPIDE after its been deployed, so the delay will give you time to open the window and catch the output.

its a timing thing


JordanR

Tue, 06 Nov 2012 22:29:33 +0000

Hello newtothesethings,

The problem is that you have selected chipKIT MAX32-USB For Serial as you Board. Just use chipKIT MAX32. I actually made this mistake as well when I first used MPIDE. I believe that when you select chipKIT MAX32-USB for Serial, the Max32 will try to use the USB control module (in the microcontroller), which means it will be trying to use the USB receptacles on the chipKIT Network Shield. Someone please correct me if I am wrong, but I believe that is the purpose.

When you use a Serial object, you are simply initializing a UART (in your case you are using UART1, which is connected directly to the USB-Serial interface on your Max32. Hope this helps!

Best Regards

Jordan R


newtothesethings

Tue, 06 Nov 2012 22:46:52 +0000

BloodyCatcus - I tried the delay method to no avail. Although it may have been part of the problem.

JordanR - That fixed it! I am so happy to get past this bump in the road.

Thanks for the responses!


EmbeddedMan

Wed, 07 Nov 2012 01:05:41 +0000

Jordan is absolutely correct. If you select the "usb" version of a board (or a board which defaults to USB serial, like FubarinoSD, FubarinoMini, UBW32, etc.) then the core library code will select the USB port when you use the Serial object. If you want to talk to the real UART (serial) ports on those boards, you can, using Serial0, Serial1, Serial2, etc.

*Brian


newtothesethings

Wed, 07 Nov 2012 03:55:05 +0000

Alright, that makes sense to me. I don't understand the details exactly, but the overall concept is clear.

I can now run some of the examples such as PhysicalPixel from MPIDE. When I type the corresponding values into the serial monitor they turn my LED on and off as expected.

Sending values through the serial monitor is a step in the right direction, but my next goal is to use Processing to accomplish the same task. The PhysicalPixel example includes Processing code to do this, but is doesn't work for me. My receive LED on the board lights up when Processing is running, but the LED that is supposed to turn on and off at mouse-over does nothing.

So I was wondering, is this not working because of a similar serial issue as before that I don't understand? If it is, is there anywhere I can get more information on the topic? Solutions are also appreciated as always. The two sets of code are below for reference.

Thanks!

MPIDE Code:

/*
  Physical Pixel
 
 An example of using the Arduino board to receive data from the 
 computer.  In this case, the Arduino boards turns on an LED when
 it receives the character 'H', and turns off the LED when it
 receives the character 'L'.
 
 The data can be sent from the Arduino serial monitor, or another
 program like Processing (see code below), Flash (via a serial-net
 proxy), PD, or Max/MSP.
 
 The circuit:
 * LED connected from digital pin 13 to ground
 
 created 2006
 by David A. Mellis
 modified 14 Apr 2009
 by Tom Igoe and Scott Fitzgerald
 
 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/PhysicalPixel
 */

const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
    } 
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
    }
  }
}

Processing Code:

// mouseover serial 
 
 // Demonstrates how to send data to the Arduino I/O board, in order to 
 // turn ON a light if the mouse is over a square and turn it off 
 // if the mouse is not. 
 
 // created 2003-4
 // based on examples by Casey Reas and Hernando Barragan
 // modified 18 Jan 2009
 // by Tom Igoe
 // This example code is in the public domain.

 
 
 import processing.serial.*; 
 
 float boxX;
 float boxY;
 int boxSize = 20;
 boolean mouseOverBox = false;
 
 Serial port; 
 
 void setup()  {
 size(200, 200);
 boxX = width/2.0;
 boxY = height/2.0;
 rectMode(RADIUS); 
 
 // List all the available serial ports in the output pane. 
 // You will need to choose the port that the Arduino board is 
 // connected to from this list. The first port in the list is 
 // port #0 and the third port in the list is port #2. 
 println(Serial.list()); 
 
 // Open the port that the Arduino board is connected to (in this case #0) 
 // Make sure to open the port at the same speed Arduino is using (9600bps) 
 port = new Serial(this, Serial.list()[4], 9600);  //I did update this line to [4]
 
 }
 
 void draw() 
 { 
 background(0);
 
 // Test if the cursor is over the box 
 if (mouseX > boxX-boxSize && mouseX < boxX+boxSize && 
 mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
 mouseOverBox = true;  
 // draw a line around the box and change its color:
 stroke(255); 
 fill(153);
 // send an 'H' to indicate mouse is over square:
 port.write('H');       
 } 
 else {
 // return the box to it's inactive state:
 stroke(153);
 fill(153);
 // send an 'L' to turn the LED off: 
 port.write('L');      
 mouseOverBox = false;
 }
 
 // Draw the box
 rect(boxX, boxY, boxSize, boxSize);
 }