Here is a special treat for those of you who look at this. I have taken some video of the project that got me my undergrad research. Here is my DC motor controlling Sun Spot in action. Here, the Sun Spot connected to the car is running a bit of code that I created to manage the H-Bridge’s controls. I created an object called L298NDriver. This object takes in three of the output pins, specifically the ones that are connected to the enable and two input pins with respect to the H-Bridge being used by the motor. The L298NDrive manages what pins to set high or low depending on what direction you want to go. It also manages the Pulse Width Modulation signal being sent from the Sun Spot.
The other Sun Spot used in the program was a simple remote rigged up. It uses a trinary system to talk to the Sun Spot on the car to determine which direction to send the motors. This works because the motor is bi-directional plus when it is sitting still. So I mapped each one of these states to the number 0, 1, or 2. The remote uses three of the basic principles about the Sun Spot that I learned when I took the class last semester. The switches control the direction of the drive motor. The left switch will make it run backwards and the right switch will make it run forward. Holding no switches down puts the motor into its “free running” state. The remote also uses the accelerometer to control the steering. If I dip the Sun Spot to the left, the steering motor turns the wheels left. If I dip the Sun Spot to the right, the steering motor turns the wheels right. If I keep it close to level, the motor will be in the “free running” state. I programmed in some offsets between what is left to “free running” to right so the remote does not lock up if you turn it too fast.
I really enjoyed doing this project because it had enough electrical engineering in to to make me happy. The coding took a lot of thought as well because I wanted this thing to drive smoothly. I will eventually be making it autonomous (a robot) once I get the necessary parts and and have some free time. I will keep you followers posted on how the robot comes along and any other projects that I crank out.