Configuration of a port To Control a Step motor

I have got a 3pi Robot But I need to configure a PORT to control a Stepper motor. In the code I have a string
string[3]= {0x01, 0x02, 0x04} for example so i want that in the program i can control my motor with a for( i =0 ; i<=3, i++)
and to put in the PORT = string[i]; So I am going to have a rotation but how configure it.??


It is not clear to me what you are trying to accomplish. I suggest you post your entire program so people can take a look at it. Could you also tell us what you are trying to accomplish with the 3pi and a stepper motor? From the lines you shared, it looks like you have an error in your for loop. With the condition “i <= 3”, the loop will be executed 4 times. I think you meant to have just “i < 3” since your array size is only 3.

- Jeremy

Hello the matter is this:
I want to fabricate an automatic car. It gonna have a stepper motor that has to rotate 180°, on this one, there is a sharp distance sensor of 4 to 30 cm so It will take information about the front space and the 3pi will move to the longer distance. With its ATMega328p I want to register this information and to send it with a xbee to the computer with another xbee(explorer). So the code has to contain, lines for serial transmission, lines to control the stepper motor and lines to keep the values of distance. My problem is that I do not know how to configure a PORT to send through it a number in binary code and in that form control the stepper motor. The sensor signal can be obtained with the analog input 6 and I know the example about the serial transmission so i want to know how to join these lines of codes for control the car in the form that i said.
So the car is stopped. The motor runs and the sensor takes measures, next we compare these measures and the 3pi move in direction of the longer distance about 5cm(we define this distance with programation) next the 3pi comes back to take measures of distance so is stopped again and that is the loop, If 3pi has to turn we program it with a case or several ifs something like that. That is the idea.
I hope you can help me Thanks very much! .

It sounds like you might be trying to drive a stepper motor directly with the ATmega328’s pins. This is probably not a good idea depending on how much current your stepper motor draws. Instead, you should probably consider using a stepper motor driver to drive your motor. Using one of our stepper motor driver carriers will allow you to control a bipolar stepper motor with just two IO lines. You can read more about our stepper motor driver carriers on their product pages. You might find the wiring diagrams in the “Using the driver” section under the “Description” tab on the product pages helpful.

You should be able to send serial data to an XBee using the USART pins (PD0 and PD1). By the way, have you seen our m3pi expansion kit? It provides an easy way to integrate wireless modules like the XBee.

- Jeremy

Thank you very much!
The driver was usefull but I have a better idea and It is to control all with a arduino mega 2560. I live in Colombia near Ecuador so It is so dificult to get the kid so, How can I connect arduino without the kid?. My idea is to control the 3pi robot with arduino througth serial comands and with other serial port in arduino connect the Xbee in a peer to peer network because I am gonna use a distance sensor SHARP that I said, and the information obtained will be analized with Matlab doing it in a automatic form when 3pi is recognizing a place; and too, 3pi must to have the hability to be controled by a kind of a joystick when it is not recognizing.
Is it posible with 3pi?.
And another thing, that is not in relation with the lines before and It is for a challengue. There is a challengue about line follower but the line is white How can I change de example code in this page about line follower to that the 3pi robot follow a white line.?
Thanks very much!

It should be possible to connect the 3pi and XBee to an Arduino Mega and control the 3pi from the it. You can use the same serial communications pins (PD0 and PD1) to connect your Arduino to the 3pi. You might find our serial slave program helpful for controlling the 3pi with the Arduino. With the serial slave program loaded onto the 3pi, you can send commands to control various features of the 3pi. You can find more information about this in the “Serial slave program” section of the 3pi user’s guide. (We also have a Spanish version of the user’s guide that a customer made.)

Is the white line on a dark surface? If so, the only change you should have to make to the example 3pi code to follow a white line is replacing the read_line() function calls with read_line_white(). You might find this forum thread on the topic helpful.

- Jeremy

Thank you very much! I am very grateful with you.
with the matter about arduino Xbee and 3pi:
So, I can not use the serial slave program that is in this page as example.?¿Why? How can I find a serial slave program that be accord to arduino? what are the thing that I have to take care in?

The serial master program can be used to control a 3pi with the serial slave program loaded onto it. We do not have a version of the serial master program that was meant to run on an Arduino, but you might be able to reference it for hints on writing your own program. Alternatively, you can refer to the commands listed in the “Serial slave program” section of the 3pi guide to write your own program.

- Jeremy

I need help please, the matter is this i have a code in arduino like this:

[code]void setup() {
Serial.begin(115200); // begin serial communications at 115200 bps
void loop() {

if (Serial.available()>0) {
while(Serial.available()>0){ // while bytes remain in the serial
// buffer

Serial.print(“ASCII Character Value of Byte Read: \n”);
Serial.print(“ASCII Decimal Value of Byte Read: \n”);

// to myByte

It is a code to send information for TTL serial protocole by arduino but Serial.print(0xb5) It is not send like this because 3pi robot writes in Lcd Bad cmd 33 so How can I send the comands by arduino to that the 3pi understand.?

Serial.print() converts the value inside to ASCII and will not work for sending commands to the 3pi. You should use Serial.write() instead of Serial.print().

- Jeremy