Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Newbie question: Error message: PoloMotor1:17:1: error: a function-definition is not allowed here before '{' token {


#5

Hello, Gam.

It appears as though you pasted our example code into the void loop() function of a blank example sketch. Our program has its own loop function and is meant to replace the code in the example sketch in its entirety. Can you try replacing your entire code in the Arduino IDE with the example code in our user’s guide?

-Nathan


#6

Nathan, you are absolutely correct, that fixed it. Again, apologies.


#7

Another question, please.

If I want to independently control three motors, do I need to use three High-Power Simple Motor Controllers G2 24v12?

And would have to have three windows running (with the Simple Motor Controller Center?)

I’m planning on running twenty four motors…and twenty windows running (with the Simple Motor Controller Centers) would be cumbersome!


#8

Arduino Uno With Pololu 1365. High-Power Simple Motor Controller G2 24v19,

Code directly from page 102 of Pololu Simple Motor Controller G2 User’s Guide

How to fix:
a function-definition is not allowed here before ‘{’ token

Using library SoftwareSerial at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SoftwareSerial
exit status 1
a function-definition is not allowed here before ‘{’ token

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10808 -build-path C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_141489 -warnings=none -build-cache C:\Users\ADMINI~1\AppData\Local\Temp\arduino_cache_583568 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose C:\Users\Administrator\Documents\Arduino\PoloMotor1\PoloMotor2\PoloMotor2.ino
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10808 -build-path C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_141489 -warnings=none -build-cache C:\Users\ADMINI~1\AppData\Local\Temp\arduino_cache_583568 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose C:\Users\Administrator\Documents\Arduino\PoloMotor1\PoloMotor2\PoloMotor2.ino
Using board 'uno' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr
Detecting libraries used...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_141489\\sketch\\PoloMotor2.ino.cpp" -o nul
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_141489\\sketch\\PoloMotor2.ino.cpp" -o nul
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src\\SoftwareSerial.cpp" -o nul
Generating function prototypes...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_141489\\sketch\\PoloMotor2.ino.cpp" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_141489\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_141489\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_141489\\sketch\\PoloMotor2.ino.cpp" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_141489\\sketch\\PoloMotor2.ino.cpp.o"
C:\Users\Administrator\Documents\Arduino\PoloMotor1\PoloMotor2\PoloMotor2.ino: In function 'void loop()':

PoloMotor2:29:1: error: a function-definition is not allowed here before '{' token

 {

 ^

PoloMotor2:128:1: error: expected '}' at end of input

 }

 ^

Using library SoftwareSerial at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SoftwareSerial 
exit status 1
a function-definition is not allowed here before '{' token

#9

There are a few options for controlling multiple Simple Motor Controllers (SMCs). Multiple SMCs can be connected and controlled from a microcontroller like the Arduino Uno you mentioned. The connections for daisy-chaining several SMCs are discussed in the Serial daisy chaining section of the SMC User’s Guide. The addressing scheme and communication protocols for working with several daisy-chained SMCs is discussed in the Serial and I²C settings and Binary commands sections of the User’s guide.

Alternatively, if you want to control several SMCs using the USB interface of a PC, you can call the smcg2cmd command line utility (which is included with our Simple Motor Controller G2 Software and Drivers for Windows). For more about this utility, I recommend opening the full SMC user’s guide in your web browser and searching in the document (for most browsers, <Ctrl + F> will bring up the “find in page” function) for the keyword “smcg2cmd”.

Finally, if you are comfortable with C development and communicating with USB peripherals natively, you might look at the Example native USB code in C#, Visual C++, and VB .NET section of the user’s guide, which has links to the Pololu USB Software Development Kit

Please let us know if you have any specific questions or find anything unclear after reviewing those resources.

-Nathan


#10

I am trying to daisy chain three G2 Simple Motor Controllers together. But control each motor separately (speed up, speed down and reverse)

I am using an Arduino Uno and three 1365 (High-Power Simple Motor Controller G2 24v12)

The first line of the Sketch says

#include <SoftwareSerial.h>

  1. I guess that is the Pololu protocol?

  2. I changed the input settings of the Motor Control Center G2 for each 1365. The master is device number 13, the first slave is device number 14 and the second slave device number 15

  3. The TX of master 1365 is connected to the RX of each 1365.

  4. The TX of slave 1 is connected RX of the master

  5. Where does the Arduino output go to on the master?

(If the TX of slave 1 is connected RX of the master. In the example on Page 101/128 https://www.pololu.com/docs/0J77)

Pin 5 went the master Pin 3, RX/SDA)

  1. The TXIN of slave 1 is connected TX of slave 2

While the program in the documentation (page 101/128.) works for one motor

#include &lt;SoftwareSerial.h&gt;

#define rxPin 3 // pin 3 connects to smcSerial TX (not used in this example)

#define txPin 5 // pin 5 connects to smcSerial RX

SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);

I do not know how to write the code to separately control the motors.


#11

The #include <SoftwareSerial.h> is a general purpose Arduino library that allows serial communication using pins that on the microcontroller do not have a hardware UART. You can read more about the library on the softwareSerial reference page on the Arduino site.

In the context of your post, the software serial port is used to select two of the Arduino’s pins for it to send and receive serial data over. Specifically, in the example code you posted, the Arduino will toggle pin 5 to transmit data to and monitor pin 3 to receive transmissions from attached devices like the SMC. So in our wiring diagrams in the"Connecting a serial device" section of the SMC user’s guide, Pin 5 is the Arduino’s TX (transmit) pin and pin 3 is the RX (receive) pin.

If you are not familiar with serial communication protocols or serial communications in the Arduino environment, there are a number of resources like this Sparkfun tutorial available on the web that might be helpful for you to review.

The Pololu Protocol specifies the bytes to send over the serial interface so that the attached devices know which commands to respond to and which to ignore. To modify the “Simple example” code in section 8.4 of the SMC user’s guide to tell your master device (ID=13) to exit safe-start using the Pololu protocol, you would need to send 3 bytes and line 10 would become:

smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0D);          //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start

You can find more documentation of these bytes in the “Binary command reference” section of the SMC user’s guide.

By the way, we noticed you posted your question 4 separate times on our forum. That clutters our forum, (and it might not be clear to other posters that your questions have been addressed) so we have deleted the duplicate posts. Please refrain from posting duplicates of your questions.

-Nathan


#12

Please, how do I individually (separately) control three daisy-chained Simple Motor Controllers SMCs (Pololu item 1365: High-Power Simple Motor Controller G2 24v12). I want to control the SMCs separately, i.e., motor 1 on SMC 13 half speed counterclockwise, motor 2 on SMC 14 clockwise half speed, motor 3 on SMC 15 counterclockwise full speed?

I am using an Arduino Uno with three SMCs. The Device numbers have been changed, 13 (master), 14, 15.
I am using #include <SoftwareSerial.h>

Arduino toggles pin 5 to transmit data to and monitor pin 3 to receive transmissions from attached devices like the SMC.
I am also using

smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0D);          //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start

Again, thank you.


#13

The specific bytes to send to do things like move the motor are explained in the “Binary command reference” section of the user’s guide I mentioned in the last post. The bytes to send for the commands for forward and reverse using the Pololu protocol are both listed there. Please look at those and, if there is something in those instructions that is not clear, please let us know.

-Nathan


#14

Thank you

  1. Is this correct?
    To make serial daisy chained device #13 full speed forward (Pololu protocol):
    0xAA, 0x0D, 0x05, 0x00, 0x64
    Reverse Full speed Pololu Protocol 0xAA, 0x0D, 0x06, 0x00, 0x64

  2. What and where do I insert the 0xAA, 0x0D, 0x05, 0x00, 0x64 in the code below?

Thank you

#include <SoftwareSerial.h>
#define rxPin 3  // pin 3 connects to smcSerial TX  
#define txPin 5  // pin 5 connects to smcSerial RX
SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);
 
// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
{
smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0D);          //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start
}
 
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{
  if (speed < 0)
  {
    smcSerial.write(0x86);  // motor reverse command
    speed = -speed;  // make speed positive
  }
  else
  {
    smcSerial.write(0x85);  // motor forward command
  }
  smcSerial.write(speed & 0x1F);
  smcSerial.write(speed >> 5 & 0x7F);
}
 
void setup()
{
  // Initialize software serial object with baud rate of 19.2 kbps.
  smcSerial.begin(19200);
 
  // The Simple Motor Controller must be running for at least 1 ms
  // before we try to send serial data, so we delay here for 5 ms.
  delay(5);
 
  // If the Simple Motor Controller has automatic baud detection
  // enabled, we first need to send it the byte 0xAA (170 in decimal)
  // so that it can learn the baud rate.
  smcSerial.write(0xAA);
 
  // Next we need to send the Exit Safe Start command, which
  // clears the safe-start violation and lets the motor run.
  exitSafeStart();
}
 
void loop()
{
  setMotorSpeed(3200);  // full-speed forward
  delay(8000);
setMotorSpeed(-1000);  // half-speed reverse
  delay(4000);
 setMotorSpeed(1000);  // half-speed forward
  delay(4000);
  setMotorSpeed(-3200);  // full-speed reverse
  delay(10000);
  setMotorSpeed(3200);  // full-speed forward
  delay(8000);
setMotorSpeed(-1000);  // half-speed reverse
  delay(4000);
 setMotorSpeed(1000);  // half-speed forward
  delay(4000);
  setMotorSpeed(-3200);  // full-speed reverse
  delay(10000);
}

#15

Yes, that series of bytes will command the #13 device to go full forward and then full reverse. The specific place those would go depends on the timing of when you would want them to run, but in general, you would run them after the exit safe-start commands run. You could replace any of the setMotorSpeed(); statements in the ‘void loop()’ function in that example with a series of smcSerial.write() commands that send the appropriate bytes like that. The Arduino IDE uses C++ language and there are some simple program examples like the Blink sketch (with associated tutorials on the Arduino web site) included that might be helpful for you to work through to see how the code written in the IDE executes.

-Nathan


#16

When I replaced `setMotorSpeed() with
smcSerial.write(0xAA, 0x0D, 0x05, 0x00, 0x64); //set motor 1 full speed forward
I get this error: no matching function for call to ‘SoftwareSerial::write(int, int, int, int, int)’

Verbose Error message

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10808 -build-path C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_543807 -warnings=none -build-cache C:\Users\ADMINI~1\AppData\Local\Temp\arduino_cache_823002 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose C:\Users\Administrator\Documents\Arduino\Indiv_Motor1_modified_Pin4_5_Rx\Indiv_Motor1_modified_Pin4_5_Rx.ino
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\Administrator\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10808 -build-path C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_543807 -warnings=none -build-cache C:\Users\ADMINI~1\AppData\Local\Temp\arduino_cache_823002 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-5.4.0-atmel3.6.1-arduino2.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino14.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose C:\Users\Administrator\Documents\Arduino\Indiv_Motor1_modified_Pin4_5_Rx\Indiv_Motor1_modified_Pin4_5_Rx.ino
Using board 'uno' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr
Detecting libraries used...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_543807\\sketch\\Indiv_Motor1_modified_Pin4_5_Rx.ino.cpp" -o nul
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_543807\\sketch\\Indiv_Motor1_modified_Pin4_5_Rx.ino.cpp" -o nul
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src\\SoftwareSerial.cpp" -o nul
Generating function prototypes...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_543807\\sketch\\Indiv_Motor1_modified_Pin4_5_Rx.ino.cpp" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_543807\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_543807\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10808 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\libraries\\SoftwareSerial\\src" "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_543807\\sketch\\Indiv_Motor1_modified_Pin4_5_Rx.ino.cpp" -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\arduino_build_543807\\sketch\\Indiv_Motor1_modified_Pin4_5_Rx.ino.cpp.o"
C:\Users\Administrator\Documents\Arduino\Indiv_Motor1_modified_Pin4_5_Rx\Indiv_Motor1_modified_Pin4_5_Rx.ino: In function 'void loop()':

Indiv_Motor1_modified_Pin4_5_Rx:51:45: error: no matching function for call to 'SoftwareSerial::write(int, int, int, int, int)'

 smcSerial.write(0xAA, 0x0D, 0x05, 0x00, 0x64);   //set motor 1 full speed forward

                                             ^

In file included from C:\Users\Administrator\Documents\Arduino\Indiv_Motor1_modified_Pin4_5_Rx\Indiv_Motor1_modified_Pin4_5_Rx.ino:1:0:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SoftwareSerial\src/SoftwareSerial.h:102:18: note: candidate: virtual size_t SoftwareSerial::write(uint8_t)

   virtual size_t write(uint8_t byte);

                  ^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SoftwareSerial\src/SoftwareSerial.h:102:18: note:   candidate expects 1 argument, 5 provided

In file included from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Stream.h:26:0,

                 from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,

                 from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:232,

                 from C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_543807\sketch\Indiv_Motor1_modified_Pin4_5_Rx.ino.cpp:1:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:57:12: note: candidate: size_t Print::write(const char*, size_t)

     size_t write(const char *buffer, size_t size) {

            ^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:57:12: note:   candidate expects 2 arguments, 5 provided

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:56:20: note: candidate: virtual size_t Print::write(const uint8_t*, size_t)

     virtual size_t write(const uint8_t *buffer, size_t size);

                    ^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:56:20: note:   candidate expects 2 arguments, 5 provided

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:52:12: note: candidate: size_t Print::write(const char*)

     size_t write(const char *str) {

            ^

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Print.h:52:12: note:   candidate expects 1 argument, 5 provided

Using library SoftwareSerial at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SoftwareSerial 
exit status 1
no matching function for call to 'SoftwareSerial::write(int, int, int, int, int)'
#include <SoftwareSerial.h>
#define rxPin 3  // pin 3 connects to smcSerial TX  (not used in this example)
#define txPin 4  // pin 4 connects to smcSerial RX
#define txPin 5  // pin 5 connects to smcSerial RX
SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);
 
// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
{
  smcSerial.write(0x83);
}
 
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{
  if (speed < 0)
  {
    smcSerial.write(0x86);  // motor reverse command
    speed = -speed;  // make speed positive
  }
  else
  {
    smcSerial.write(0x85);  // motor forward command
  }
  smcSerial.write(speed & 0x1F);
  smcSerial.write(speed >> 5 & 0x7F);
}
 
void setup()
{
  // Initialize software serial object with baud rate of 19.2 kbps.
  smcSerial.begin(19200);
 
  // The Simple Motor Controller must be running for at least 1 ms
  // delay here for 5 ms.
  delay(5);
 
  // If the Simple Motor Controller has automatic baud detection
  // enabled, send the byte 0xAA (170 in decimal)
  // so that it can learn the baud rate.
  smcSerial.write(0xAA);
 
  // Exit Safe Start command, 
  // clears the safe-start violation and lets the motor run.
  exitSafeStart();
}
 
void loop()
{
smcSerial.write(0xAA, 0x0D, 0x05, 0x00, 0x64);   //set motor 1 full speed forward
  delay(8000);
setMotorSpeed(-1000);  // half-speed reverse
  delay(4000);
 setMotorSpeed(1000);  // half-speed forward
  delay(4000);
  setMotorSpeed(-3200);  // full-speed reverse
  delay(10000);
  setMotorSpeed(3200);  // full-speed forward
  delay(8000);
setMotorSpeed(-1000);  // half-speed reverse
  delay(4000);
 setMotorSpeed(1000);  // half-speed forward
  delay(4000);
  setMotorSpeed(-3200);  // full-speed reverse
  delay(10000);
}

#17

Thank you, Jonathankosh! It worked. Motor 13 works fine. To control the motor 14,
copied and pasted with smcSerial.write(0x0E) in a number of places. I always get an error: ‘smcSerial’ does not name a type

Please, where do I insert the code to control motor 14?

This is what I tried.


#include <SoftwareSerial.h>
#define rxPin 3  // pin 3 connects to smcSerial TX  
#define txPin 5  // pin 5 connects to smcSerial RX
SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);
 
// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
{
smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0D);          //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start
}
{
smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0E);          //This lets device number 14 (0x0E in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start
}
 
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{
  if (speed < 0)

//code continues as in your example
[\code]



// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
{
smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0D);          //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start
}
 
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{

#18

The smcSerial.write() function in our library only accepts a single byte at a time, so you will need to call the function 4 times (on 4 separate lines) to pass all 4 bytes (just like the example code I posted a week ago to exit safe-start using the Pololu protocol uses the smcSerial.write() function 3 separate times to send 3 bytes).

-Nathan


#19

Thanks. I appreciate the help. Jonathankosh also sent me the code, it worked. Motor 13 works fine. To control the motor 14, copied and pasted with smcSerial.write(0x0E) in a number of places. I always get an error: ‘smcSerial’ does not name a type

Please, where do I insert the code to control motor 14?

This is what I tried.

#include <SoftwareSerial.h>
#define rxPin 3  // pin 3 connects to smcSerial TX  
#define txPin 5  // pin 5 connects to smcSerial RX
SoftwareSerial smcSerial = SoftwareSerial(rxPin, txPin);
 
// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
{
smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0D);          //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start
}
{
smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0E);          //This lets device number 14 (0x0E in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start
}
 
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{
  if (speed < 0)

//code continues as in your example


// required to allow motors to move
// must be called when controller restarts and after any error
void exitSafeStart()
{
smcSerial.write(0xAA);          //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0D);          //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03);          //This is the specific command to tell the addressed device to exit safe-start
}
 
// speed should be a number from -3200 to 3200
void setMotorSpeed(int speed)
{


#20

The set of statements you added to make device 14 exit safe-start are in the correct format, but you have placed them outside of the exitSafeStart() function (and outside of any other functions) in your program. Also, there is no single correct place for any of this code; the placement will depend on how you want the program to behave.

In general, our technical support is not the best place to get help with basic syntax and code structure for a common language like C++ (which the Arduino IDE uses). There are numberous online courses, tutorials, and documentation for learning a language like that. If you are looking for a more personal approach, you might try finding someone who is familiar with writing programs for Arduino to help you out with your project at some place like a local hackerspace.

-Nathan


#21

I am yet trying to get the second motor to work.

From your instructions:
“The set of statements you added to make device 14 exit safe-start are in the correct format, but you have placed them outside of the exitSafeStart() function (and outside of any other functions) in your program. Also, there is no single correct place for any of this code; the placement will depend on how you want the program to behave.”

I tried this and did not work.

void exitSafeStart()
{
smcSerial.write(0xAA); //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0D); //This lets device number 13 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03); //This is the specific command to tell the addressed device to exit safe-start
}

void exitSafeStart()
{
smcSerial.write(0xAA); //This lets all of the attached devices know that this is the start of a Pololu protocol command packet
smcSerial.write(0x0E); //This lets device number 14 (0x0D in hex) know that it is the target of the command (and lets all other devices know they do not respond to the command)
smcSerial.write(0x03); //This is the specific command to tell the addressed device to exit safe-start
}

I am sorry about all the questions.Yes, I have tried other forums, including Arduino. And read the two standard books. This program is way more complex than the “Blink” and has Pololu propriety code that no one else understands. Again thank you.


#22

Hello.

It looks like you are trying to define a new function with the exact same name as your previous one (exitSafeStart()). I suspect you would be getting an error about redefining the exitSafeStart() function if you try to compile that code. If you want to have separate functions for sending the exit safe start command to each controller like that, you should give them unique names. Also, note that you would need to call each function separately for them to both run.

Alternatively, you could just move the second set of serial bytes to the first function (and erase the duplicate function) if you always want to send the exit safe start command to both controllers.

By the way, the only thing specific to the Simple Motor Controller in your code is the bytes you are sending, which Nathan has already confirmed are correct. The syntax and code structure of C++ (which is what you seem to be having problems with now) is not specific to our Simple Motor Controller’s serial protocol.

Brandon


#23

Hello BrandonM

Thank you for the reply.

" If you want to have separate functions for sending the exit safe start command to each controller like that, you should give them unique names."

Like this?

motor1.exitSafeStart();
motor2.exitSafeStart();
motor3.exitSafeStart();

Or like this?

exitSafeStart(motor1);
exitSafeStart(motor2);
exitSafeStart(motor3);

Thank you


#24

Hello, Gam.

This tutorial about creating functions using the Arduino IDE (which uses the C++ language) might be helpful for you:

https://startingelectronics.org/software/arduino/learn-to-program-course/15-functions/

-Nathan