Arduino and 2s12v10

A friend just gave me his used Arduino Mega 2560 and 2s12v10. I am fairly new to electronics but I feel I understand the basics. I am trying to control a DC motor with these two set-up.

I first started with a sketch, that as far as I could tell tested if the 2560 and 2s12v10 were communicating. By using the Serial Monitor, it successfully returned my input in bits.

int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

However, when trying to actually control the motor; I have been unsuccessful. I have tried following the advice in similar threads but cannot get the motor to work. I have been using the following code, which I altered to meet the newest version of Arduino (downloaded today):

void setup() 
{
  Serial.begin(9600);
  Serial.write(0xAA);
  Serial.write(0x8E);
  Serial.write(63);
}
void loop()
{
}

The status light never changes the rate at which it blinks; roughly once per second. From what I gather this means that it is not receiving the baud rate? The Ardiuno’s ‘TX’ and ‘RX’ lights blink when the sketch is uploaded. The 2s12v10 and motor are running on 6 V (power supply) and I have run the motor separably at the same voltage and worked perfectly.

I have a feeling that I am making a simple mistake, as I have not even had this set-up a day. Any help would be greatly appreciated. Thank you.

Hello.

Can you tell me how you have everything connected? Also, to simplify things, can you disconnect your motor from the qik and just use its indicator LEDs as feedback for now?

- Ben

Sure, I have disconnected the motor from the qik.

The Arduino board is connected to my computer via USB. The transmit connection from the qik is going to RX1 (19) on the 2560 and the receive connection from the qik is going to TX1 (18) on the 2560. I also have the ground from the qik to the ‘Power’ GND on the 2560. These are connected with a 5 pin connector (not sure what the technical name is).

Thank you for your help.

Pins 18 and 19 on the Arduino Mega correspond to serial port 1 (Serial1). Please let me know if changing your code as follows helps:

void setup() 
{
  Serial1.begin(9600);
  Serial1.write(0xAA);
  Serial1.write(0x8E);
  Serial1.write(63);
}

- Ben

Yup, that worked! Thank you for the help. I could have sworn I read that the serial numbering went Serial, Serial2, Serial3. Guess not.

Thanks again

Another quick question. When I am running an Arduino script of mine the red ERR led turns on. I know that, in order to read the error byte you use: Serial1.write(0x82); However, when trying to read the byte with: incomingByte = Serial1.read(); Serial1.println(incomingByte);
I do not receive anything in the Serial Monitor, although the ERR light does turn off. Is there another way I should be trying to read the byte when sent by the qik?

Thank you.

I’m glad to hear that got it working. The serial monitor is connected to serial port 0, or Serial, so if you want to print something to it, you need to use:

Serial.println(incomingByte);

Your program is currently sending the error byte back to the qik.

- Ben

Sorry Ben, have a question regarding the error code.

I’m simply trying to get a motor going again as I was with the first post here. However, using the same code I have been unsuccessful. The red ERR light turns on, but I cannot get the Serial Monitor to read the error. How exactly should I go about this, I tried doing the following:

int incomingByte;

void setup() 
{
  Serial1.write(0xAA); 
  Serial1.begin(9600);
  Serial1.write(0x8E);
  Serial1.write(63);
  Serial1.write(0x82);
  incomingByte = Serial1.read();
  Serial.println(incomingByte);
}

void loop()
{
}

But this is not working when I open up the Serial Monitor, how exactly should I change this? Thank you for your help!

Hello. Maybe Ben will see some other problems with your code, but it seems like a bad idea to send the 0xAA byte before you have defined the baud rate of your UART.

–David