PenguibBotLib, my library for Elegoo Penguin bot

An Arduino library to program the Penguin Bot by Elegoo in an easier way,

Ottobre 12, 2024

Introduction

I was called to arrange a robotics course for young guys (12-13 years old) and I’ve decided to use the Elegoo Penguin bot robot kit with the Arduino Nano microcontroller, which is similar to the open project Otto.

The kit hardware had a problem with the developer/bluetoorh switch, and that’s really a pity which prevents you to upload new code unless you remove the Arduino Nano from the board. So, I’ve contacted Elegoo to get the fixed parts… (Still waiting one month later).

Moreover I’ve found some difficulties in using their library, too many files, too many includes to explain to young newbies students. So I partially rewrote/remixed the original library to simplify the usage of the bot hardware.

Penguin library improvements

Some of the things I’ve changed:

  • separated mp3 driver class to MY1690_16S.cpp a nd MY1690_16S.h
  • removed not used code (functions, variables, defines)
  • renamed functions with more correct names (ex: ir is infrared, but in Penguin v.2 there is bluetooth not ir)
  • separated most of the code from main PeguinBot.ino file to penguin.cpp and penguin.h which now is a class
  • made t (time unit) optional for class methods, to simplify usage
  • also changed volume functionalities
  • pack everything into an Arduino IDE library, with examples
  • added methods to access sensor values (ir, distance and battery)
  • added method to turn on and off the light
  • the original PeguinBot.ino now is an example file and it has all the original functionalities of the original software
  • added more examples
  • added more sounds

I’ve uploaded the library in the Arduino global repository so it is available directly in Arduino IDE.

With this library quite all the features are accessible through a single “Penguin” like in this simple example:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
#include <PenguinBotLib.h>
 
Penguin robot;
 
void setup()
{
  robot.servoInit();
  robot.servoAttach();
  robot.homes(200);
  delay(2000);
}
 
int steps = 3;
void loop()
{
  robot.walk( 2 * steps, 1);
  robot.turn( steps, 1);
}

Here are some of the available methods:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* movement methods */
bool walk(int steps, int dir, int T = -1);
bool moveNServos(int time, int newPosition[]);
bool delays(unsigned long ms);
void servoAttach();
void servoDetach();
void servoInit();
void resetTrim ();
bool home();
void homes(int T = -1);
bool oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]);
bool turn(int steps, int dir, int T = -1);
bool moonWalkRight(int steps, int T = -1);
bool moonWalkLeft(int steps, int T = -1);
bool crusaito(int steps, int T = -1);
bool swing(int steps, int T = -1);
bool upDown(int steps, int T = -1);
bool flapping(int steps, int T = -1);
bool run(int steps, int T = -1);
bool backyard(int steps, int T = -1);
bool goingUp(int T = -1);
bool drunk(int T = -1);
bool noGravity(int T =-1);
bool kickLeft(int T=-1);
bool kickRight(int T=-1);
bool legRaise(int dir, int T=-1);
bool legRaise1(int dir, int T=-1);
bool legRaise2(int steps, int dir, int T=-1);
bool legRaise3(int steps, int dir, int T=-1);
bool legRaise4(int dir, int T = -1);
bool sitdown();
bool lateral_fuerte(boolean dir, int T=-1);
 
/* bt serial command */
void setSerialFlag(boolean flag);
bool getSerialFlag();
char getBluetoothValue();
void setBluetoothValue(char v);
void getCommand();
 
/* settings */
void trimServo(char btn);
 
/* startup anim */
void startAnimation();
 
/* sensor methods */
int getDistance();
void setThresholdIr(int v);
int getThresholdIr();
int irLeft();
int irRight();
 
/* light */
void indicatorOn();
void indicatorOff();
 
 
double getBatteryLevel();
void Test_voltageMeasure(void);

And more… there are mp3 files methods with the My1690_16S class included in the package.

Examples files included in the PenguiBotLib:

  • SensorsCheck.ino : show the values of sensors
  • Followmode.ino : follow a near target
  • ObstacleMode.ino : avoid an obstacle
  • ObstacleModeWithSound.ino : avoid an obstacle
  • Walkround.ino : walk around if there are no obstacles
  • PenguinBot.ino: refactor of the original code with all functionalities
  • WithoutLibs.ino : an example of accessing servos and sensors without using libs

The library is on Github and in the Arduino repository:

https://github.com…/PenguinBotLib

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Comments on “PenguibBotLib, my library for Elegoo Penguin bot”

Lascia un commento

Your email address will not be published. Required fields are marked with an *

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies.READ MORECLOSE