- C++ 90%
- C 10%
| include | ||
| lib | ||
| src | ||
| test | ||
| .gitignore | ||
| library.json | ||
| platformio.ini | ||
| README.md | ||
Studuino drivers for PIO (and Arduino IDE)
This project aims to simplify programming Studuino boards (specifically the "Mérd Magad" physics kit from Abacusan) in c++, just because i dont like Scratch.
The code currently has 2 parts: the DC motor drivers (studuino_motor.h) and sensor drivers (studuino_sensor.h)
Motor driver
The board uses a TB6552FNG as the motor driver IC.
The pin layout is the following:
| Function | MCU pin |
|---|---|
A_{in_1} |
D2 |
A_{in_2} |
D4 |
A_{pwm} |
D3 |
B_{in_1} |
D7 |
B_{in_2} |
D8 |
B_{pwm} |
D5 |
When a motor channel is active, the corresponding pins can not be used. You have to keep this in mind when hooking up servos, or sensors.
Enums
Motor
STUDUINO_MOTOR1: M1 motor channel (value=1)STUDUINO_MOTOR2: M2 motor channel (value=2)
Direction:
STUDUINO_DIRECTION_CW: Rotation direction - clockwise (value=0)STUDUINO_DIRECTION_CCW: Rotation direction - counter clockwise (value=1)
Usage
Almost everyhing has been abstarcted regarding the motor controls.
-
initMotor(int motor):Initializes a motor channel. Because the pins are fixed can automatically be set up.
motor: Channel ID of the motor (values in theMotorenum) -
runMotor(int motor, int direction, uint8_t value):Starts a motor
motor: Channel ID of the motor (values in theMotorenum)direction: Sets the rotation direction (values in theDirectionenum)power: Sets the speed of the motor (values 0-255)
Example
#include <Arduino.h>
#include <studuino_motor.h>
void setup() {
// Initialize M1 and run the motor clockwise at full power
initMotor(STUDUINO_MOTOR1);
runMotor(STUDUINO_MOTOR1, STUDUINO_DIRECTION_CW, 255);
}
void loop() {}
Sensor drivers
Some drivers for simple sensors. For saving flash space, the sensor modules have to be manually included.
Ultrasound Distance (HCSR04)
Standard simple driver for HCSR04
-
Include the driver for usage with
#define ST_INCLUDE_ULTRASOUND -
class HCSR04(aliasUltrasoundSensor):HCSR04(uint8_t triggerPin, uint8_t echoPin)int read(): Measures the distance (in millimeters)void begin(): Sets up the pins specified in the constructor (optional if the pins are manually set up)