Hi,
First time poster, first time Arduino fiddler. TLDR: how do I control the wheels?
The long-term goal is to build a rat-operated vehicle on the Elegoo Smart Robot Car v4 chassis, using the TB6612 and MPU6050 chips. The original code at https://www.instructables.com/Rat-Operated-Vehicle/ is for the unavailable v3. The Elegoo docs I have found are less than illuminating, so I've been reading their .h files.
Currently looks like https://twitter.com/mwlauthor/status/1557056952055767040.
I disconnected the line tracking module so I could use ports A0-A2 with a JST for the touch sensors. The touch sensor prototype works fine: when I touch the wires, I see the connections on the Arduino serial port. All that remains is to write code so the touch sensors control the motors, and then assemble it as a vehicle.
I would prefer to use an API to drive the motors, rather than going straight to the pins, in the hope that people with other Elegoo SRC v4 variants would be able to reuse the code. But it doesn't work.
To illustrate my ignorance, I've boiled this to the simplest possible sketch:
-Start with the official Elegoo arduino code.
-Add a line at the top of loop() to fire the left motors, forward, at speed 200.
Uploading the code goes fine. The wheels remain stationary.
Any suggestions appreciated! Sketch follows.
/*
@Author: ELEGOO
@Date: 2019-10-22 11:59:09
@LastEditTime: 2020-12-18 14:14:35
@LastEditors: Changhua
@Description: Smart Robot Car V4.0
@FilePath:
hacked up by mwl
*/
#include <avr/wdt.h>
#include "ApplicationFunctionSet_xxx0.h"
void setup()
{
// put your setup code here, to run once:
Application_FunctionSet.ApplicationFunctionSet_Init();
wdt_enable(WDTO_2S);
}
void loop()
{
//put your main code here, to run repeatedly :
//my API call
Application_FunctionSet.CMD_MotorControl_xxx0(1 /*motor select*/, 1 /*motor direction*/, 200 /*motor speed*/ );
wdt_reset();
Application_FunctionSet.ApplicationFunctionSet_SensorDataUpdate();
Application_FunctionSet.ApplicationFunctionSet_KeyCommand();
Application_FunctionSet.ApplicationFunctionSet_RGB();
Application_FunctionSet.ApplicationFunctionSet_Follow();
Application_FunctionSet.ApplicationFunctionSet_Obstacle();
Application_FunctionSet.ApplicationFunctionSet_Tracking();
Application_FunctionSet.ApplicationFunctionSet_Rocker();
Application_FunctionSet.ApplicationFunctionSet_Standby();
Application_FunctionSet.ApplicationFunctionSet_IRrecv();
Application_FunctionSet.ApplicationFunctionSet_SerialPortDataAnalysis();
Application_FunctionSet.CMD_ServoControl_xxx0();
Application_FunctionSet.CMD_MotorControl_xxx0();
Application_FunctionSet.CMD_CarControlTimeLimit_xxx0();
Application_FunctionSet.CMD_CarControlNoTimeLimit_xxx0();
Application_FunctionSet.CMD_MotorControlSpeed_xxx0();
Application_FunctionSet.CMD_LightingControlTimeLimit_xxx0();
Application_FunctionSet.CMD_LightingControlNoTimeLimit_xxx0();
Application_FunctionSet.CMD_ClearAllFunctions_xxx0();
}