Motor Control through Serial Ports ??????????

Hello everyone, I am working on a project that a previous student left half done and the professor wants me to get it up and running except I there is no documentation for it and all there is no working code from what I can tell.

The part of the project I am stuck on is I am using a raspberry pi 3 B and this motor controller from sparkfun

https://www.sparkfun.com/products/13911

This is the fist time I work with the serial pins on any Micro controller and I have the whole System hooked up right to the best of my knowledge and I think it is my code is what is wrong

Here is my code

 #!/usr/bin/env python
from time import sleep
import sleep

ser = serial.Serial(
     port=' /dev/ttyAMA0'
     baudrate=9600,
     parity=serial.PARITY_NONE,
     stopbits=serial.STOPBITS_ONE,
     bytesize=serial.EIGHTBITS,
)
x = 0
while(x<1):
     ser.write('M0F70\n')
     ser.write('M1F70\n')
     ser.write('E\n')
     sleep(2)
     print ('stop')
     ser.write('D\n')
     sleep(2)
     x +=1

This is the code I could not copy and paste so I could not use tab for the arguments in the loops, I just used 5 spaces if you copy this code you may have to change that back into tabs when you put it in your script.**

This code runs but nothing is happening with the motors im positive it is not to do with the hardware. So I am not sure what I am doing wrong I cant seem to find any tutorial online to to work with a motor controller like this and using serial ports (RX,TX Pins).

Hi edwin8a,

I’m afraid SparkFun Tech Support cannot help debug custom code but [this section of our Hookup Guide for the Serial Controlled Motor Driver might help you configure the motor driver properly and help with sending the correct serial commands. The [SCMD Datasheet might also help you out here.

For help with setting up your script to send serial commands, a quick search turned up [this tutorial an this [reference page from the Pi Foundation could help you out here as well.](https://www.raspberrypi.org/documentation/configuration/uart.md)](https://www.elinux.org/Serial_port_programming)](Serial_Controlled_Motor_Driver/Documentation/SCMD_Datasheet.pdf at master · sparkfun/Serial_Controlled_Motor_Driver · GitHub)](Serial Controlled Motor Driver Hookup Guide - SparkFun Learn)

Issues you can have when using serial coms with the RPi is there are 2 different ports that are used depending on if the board has builtin bluetooth. Also Python handles serial coms in a strange way and then there is the encoding issues.

Use /dev/ttyAMA0 for boards without Bluetooth and /dev/ttyS0 for boards with Bluetooth.

If you want to control it over your LAN try pigpio / pigpiod.

Dale