I was wondering if I would have to change any code/connectors if I were to use an arduino mega 2560r3 rather than the uno r3-will it read the same code? Thanks
Anyone? Please. Basically I'm wondering if I will have to use different code/change the code to make the robot work with the mega r3 rather than the uno.
From the pictures you might have problems due to the sensor using i2c. On the Uno, the i2c controller is accessed on pins A4/A5 (14/15). On the Mega, the i2c pins are pins 20/21. When the Uno R3 came out, the Arduino team added 2 pins to the left of the AREF pin for the 2 pins that i2c needs, and each board then has a link from the pins on their board to those 2 pins left of the AREF pin.
From pictures I've seen online, it looks like the motor shield was designed before the Uno R3 came out, and the connection shows A4/A5 being used. Perhaps the shield has been redesigned since then to add support for the i2c pins left of AREF (and other differences in the new shield layout), and you can just use those pins. If not, you will either need to find a motor shield that is compatible with the Mega or use an Uno.
From pictures I've seen online, it looks like the motor shield was designed before the Uno R3 came out, and the connection shows A4/A5 being used. Perhaps the shield has been redesigned since then to add support for the i2c pins left of AREF (and other differences in the new shield layout), and you can just use those pins. If not, you will either need to find a motor shield that is compatible with the Mega or use an Uno.
I've never used an arduino before and I've just blown a lot of money on this project. Is there any way I can fix this with the code or will I have to get an arduino uno (looks like an r2 in the guide but it says to use an r3)
EDIT: When you say that I need to find a motor shield that is compatible with the Mega or use an Uno, will I need a uno R2 or R3. The R2 is extinct.
In thinking about it, the I2C pins on the Mega are in the larger area beyond the basic Uno pin layout. So, you should be able to wire the i2c pins directly to the Mega without buying anything else. Where the diagram has you attaching a data pin to A4, just attach it to the SDA pin on the Mega, for A5 use SCL (these are the bottom 2 pins on the right side when the usb/power are at the top). You will need to attach power and ground to the sensor as well, but you can use any power/ground pins in the shield.
MichaelMeissner:
In thinking about it, the I2C pins on the Mega are in the larger area beyond the basic Uno pin layout. So, you should be able to wire the i2c pins directly to the Mega without buying anything else. Where the diagram has you attaching a data pin to A4, just attach it to the SDA pin on the Mega, for A5 use SCL (these are the bottom 2 pins on the right side when the usb/power are at the top). You will need to attach power and ground to the sensor as well, but you can use any power/ground pins in the shield.
Sorry, I'm really new to this stuff (don't even know what the i2c pins are could you explain? ). So basically do I still insert the motor shield pins into the mega directly as shown in the diagram but I have to change the pins for the ultrasonic sensor right? Will I need to change the code much
(don't even know what the i2c pins are could you explain? ).
Forget about I2C pins.
The HC-SR04 ultrasonic sensor do not use I2C, it can use any pin you define in the setup
#include <AFMotor.h>
#include <Servo.h>
#include <NewPing.h>
#define TRIG_PIN A4 // Pin A4 on the Motor Drive Shield soldered to the ultrasonic sensor
#define ECHO_PIN A5 // Pin A5 on the Motor Drive Shield soldered to the ultrasonic sensor
You could change A4,A5 to some other pins on your Mega.
The only problem I can see is that you maybe cannot place the motorshield on top of the Mega, but you could use jumper-wires instead.
I don't have a Mega, but I'm sure others can guide you further
(don't even know what the i2c pins are could you explain? ).
Forget about I2C pins.
The HC-SR04 ultrasonic sensor do not use I2C, it can use any pin you define in the setup
If that is the case, then you should be able to use the set up as described. I assumed it used A4/A5 for I2C.
As to what I2C is, it is a bus that you can hook multiple devices to. One device is the master and the others are the slaves. Most frequently, the Arduino is the master, and the slaves are sensors that the Arduino controls, but if you are having two Arduinos, one can be slave and the other master for communication. Each slave has a unique address, and you can hook up something like 112 different boards. Some i2c devices include boards that provide multiple digital pins, analog to digital conversion, digital to analog conversion, real time clock, GPS, tilt sensor, etc. Here is a tutorial: Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino.
Here's the stock code from the website. Have no idea what to do with it to get it to work with the mega.
Could somebody give me some pointers on how to get it to work with the mega. Thanks