Hi,
Can I run the code written for UNO on Arduino Zero without any major changes?
Erica
Hi,
Can I run the code written for UNO on Arduino Zero without any major changes?
Erica
The answer, of course, is: it depends.
Most code is compatible, but you could have done something that depends upon Uno registers or depends upon how an 8-bit processor handles 16-bit arithmetic.
There are similarities and differences in the hardware support as well.
Show us the code.
vaj4088:
The answer, of course, is: it depends.Most code is compatible, but you could have done something that depends upon Uno registers or depends upon how an 8-bit processor handles 16-bit arithmetic.
There are similarities and differences in the hardware support as well.
Show us the code.
For example the following code
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
int analogInPin_1 = A0; // Analog input pin that the potentiometer is attached to
int analogInPin_2 = A1;
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue_1 = 0; // value read from the pot
int sensorValue_2 =0 ;
int outputValue_1 = 0; // value output to the PWM (analog out)
int outputValue_2 = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue_1 = analogRead(analogInPin_1);
sensorValue_2 = analogRead(analogInPin_2);
// map it to the range of the analog out:
outputValue_1 = map(sensorValue_1, 0, 1023, 0, 255);
outputValue_2 = map(sensorValue_2, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin_1, outputValue_1);
analogWrite(analogOutPin_2, outputValue_2);
// print the results to the serial monitor:
Serial.print("sensor_1 = " );
Serial.print(sensorValue_1);
Serial.print("\t output_1 = ");
Serial.println("sensor_2 = ");
Serial.println(sensorValue_2);
Serial.print("\t output_2 = ");
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2000);
}
[/CODE/]
Yes, that should run on every Arduino. There's a small modification I'd like to make for the Micro/Leonardo and it will only work on a Due if you're plugged into the Programming port instead of the Native port. But it will run and work on all of them.
What happened when you tested it?
The posted code has a comment that there is a potentiometer connected to +5 volts. I may be wrong, but isn't the Arduino Zero limited to 3.3 volts? If so, then +5 volts could do some damage, and it won't necessarily happen unless the potentiometer setting is changed.
vaj4088:
The posted code has a comment that there is a potentiometer connected to +5 volts. I may be wrong, but isn't the Arduino Zero limited to 3.3 volts? If so, then +5 volts could do some damage, and it won't necessarily happen unless the potentiometer setting is changed.
I will be careful about the 3.3V and 5.0V. The thing is that Zero board uses SAMD21G18A-AUT processor. I have two questions
If I put this SAMD21G18A-AUT processor on my board then how will program and debug it using Arduino IDE? Would be a good idea to program this processor on my board using the zero board via jumpers?
The data sheet of this processor mentions SCOM1PAD1, SCOM2PAD2, SCOM3PAD3, SCOMPAD4 . Can I use them as TXD and RXD (UART pins). Pin numbers are 19,20,21, 22, 23, 38,37. I guess I am confused about the UART pins available on this processor. Usually the processors come with pins labeled as TXD1, RXD1 etc.
Any suggestions on the identification of the RxD, TxD pins available on this processor!
Any one!