A-Star 32u4 and Arduino Uno sketch incompatibility?

Hello,

I have recently run into an issue when trying to run the sketch that i used on my Arduino Uno on the A-Star Micro, on my Arduino the code runs perfectly and does what is intended but when trying to run it on the A-Star it doesn’t power the correct pins if any at all, etc. I assume that the A-Star has a different way of defining the pins but i am not sure, here is my code:

[code]const int pingPin = 7;
const int outputPin = 12;
const int readyLedPin = 11;
const int calLedPin = 10;
int sensorValue = 0;
int sensorMax = 0;

void setup() {

pinMode(calLedPin, OUTPUT);
digitalWrite(calLedPin, HIGH);

while(millis() < 5000){
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT);
sensorValue = pulseIn(pingPin, HIGH);

if (sensorValue > sensorMax) {
  sensorMax = sensorValue - 100;
}

}

digitalWrite(calLedPin, LOW);

Serial.begin(9600);

digitalWrite(readyLedPin, HIGH);

}

void loop(){

long duration, cm;

pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

cm = microsecondsToCentimeters(duration);

Serial.print(cm);
Serial.print(“cm”);
Serial.println();

delay(100);

if (duration < sensorMax)

{
digitalWrite(outputPin, HIGH);
delay (5000);
digitalWrite(outputPin, LOW);
}
}

long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}[/code]
Help would be appreciated, Thanks.

Hello.

I am sorry you are having problems with your A-Star 32U4 Micro. The A-Star shares the same pin names as the Arduino, so you should not have to define them differently in your program. I briefly looked at your code and did not see any reason why it would not work on the A-Star. Could you tell me more about your setup? Do you have the Pololu A-Star 32U4 selected under Tools->Board in the Arduino IDE? Are you able to load other programs onto the A-Star, like the Blink example program? Could you post pictures of your setup? By the way, I noticed in your code that you call digitalWrite(readyLedPin, HIGH) without setting that pin with pinMode(). Is this intentional?

- Jeremy

Thanks for the reply,

Everything is configured properly inside the Arduino IDE and I didn’t notice that i hadn’t set a pinMode(), thanks. I noticed that the pin 13 LED is constantly flashing even when i upload my sketch and i read that the A-Star comes with ‘Blink’ installed, so would i need to re-install the bootloader?

It is unclear if you have successfully uploaded any code onto your A-Star. Do you get any errors when you upload a sketch? Are you able to load any of the example programs found under File->Examples? You should not have to reinstall the bootloader when loading any of the example programs. It is also unclear what kind of behavior you are seeing with the LED when you are uploading a sketch. How fast is it blinking? Could you post a video of it?

- Jeremy