Welcome, Guest |
You have to register before you can post on our site.
|
Latest Threads |
The Peguino Bot 1
Forum: Exhibition / Gallery
Last Post: Peguinohero
07-02-2019, 01:36 PM
» Replies: 0
» Views: 2,783
|
This is my first testentr...
Forum: Suggestions to the Peguino - how we can make it better?
Last Post: Jack
01-26-2019, 12:14 PM
» Replies: 2
» Views: 5,852
|
Peguino Gyrosensor Brick
Forum: Alle Peguino Bricks und deren Beschreibungen etc.
Last Post: Peguinohero
01-10-2019, 01:29 PM
» Replies: 0
» Views: 1,578
|
Peguino LCD Display Brick
Forum: Alle Peguino Bricks und deren Beschreibungen etc.
Last Post: Peguinohero
01-10-2019, 12:26 PM
» Replies: 0
» Views: 1,354
|
Peguino Breadboard Brick
Forum: Alle Peguino Bricks und deren Beschreibungen etc.
Last Post: Peguinohero
01-10-2019, 12:24 PM
» Replies: 0
» Views: 1,443
|
Peguino 4AA Power Brick
Forum: Alle Peguino Bricks und deren Beschreibungen etc.
Last Post: Peguinohero
01-10-2019, 11:28 AM
» Replies: 0
» Views: 1,503
|
Peguino Climate Brick
Forum: Alle Peguino Bricks und deren Beschreibungen etc.
Last Post: Peguinohero
01-10-2019, 10:27 AM
» Replies: 0
» Views: 1,396
|
Peguino Body Sensor Brick...
Forum: Alle Peguino Bricks und deren Beschreibungen etc.
Last Post: Peguinohero
01-09-2019, 07:52 PM
» Replies: 0
» Views: 1,469
|
Peguino Mikrofon Brick
Forum: Alle Peguino Bricks und deren Beschreibungen etc.
Last Post: Peguinohero
01-09-2019, 07:46 PM
» Replies: 0
» Views: 1,552
|
Peguino RC Remote Brick
Forum: Alle Peguino Bricks und deren Beschreibungen etc.
Last Post: Peguinohero
01-09-2019, 07:35 PM
» Replies: 0
» Views: 1,331
|
|
|
Welcome Guest!
|
Select the forum of your interest below. You may have to register before you can post your topic... |
The Peguino Bot 1 |
Posted by: Peguinohero - 07-02-2019, 01:36 PM - Forum: Exhibition / Gallery
- No Replies
|
 |
The Peguino Bot 1
The Peguino Bot 1 has the capability to follow a black line and can be controlled via WIFI!
See the robot in action at https://youtu.be/OJZcmLMYcnw
How to use:
1. Connect to the WIFI PeguinoBot1 and use the password peguinobot1
2. Open a webbrowser on your phone or pc's browser and type in the given IP address from the Peguino OLED Display. Usually 192.168.4.1 or type http://192.168.4.1
The Script
Code: /*
WIFI Remote Bot 1.8 Version 0.991
(C) 2019 by Peguino LTD
The Peguino Bot opens an access point to connect via WIFI.
Connect the following Bricks
Left Microprox Brick to port C3
Right Microprox Brick to Port D1
Left 360 deg Microservo Brick to C1
Right 360 deg Microservo Brick to D3
Button Brick to Port D2
Buzzer Brick to Port C2
Proximity Brick to Port A
OLED96 Display Brick to Port B
How to use:
1. Connect to the WIFI PeguinoBot1 and use the password peguinobot1
2. Open a webbrowser on your phone or pc's browser and type in the given IP address from the Peguino OLED Display. Usually 192.168.4.1 or type http://192.168.4.1
Use the Serial Plotter and Monitor to check debug values
Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐
3.3 1 │ │ 30 5V
GND 2 │ │ 29 GND
GPIO15 3 │ │ 28 GPIO13
GPIO2 4 │ │ 27 GPIO12
GPIO4 5 │ │ 26 GPIO14
GPIO16 6 │ │ 25 GPIO27
GPIO17 7 │ │ 24 GPIO26
GPIO5 8 │ │ 23 GPIO25
GPIO18 9 │ │ 22 GPIO33
GPIO19 10 │ │ 21 GPIO32
GPIO21 11 │ │ 20 GPIO35
GPIO3 12 │ │ 19 GPIO34
GPIO1 13 │ │ 18 GPIO39
GPIO22 14 │ │ 17 GPIO36
GPIO23 15 │ │ 16 Chip enable
└───┘
Visit https://www.peguino.com
*/
#include "WiFi.h"
#include "SSD1306Wire.h"
SSD1306Wire display(0x3c, 21, 22); // Pin 21 und 22 = I2C and on Connector Port B where the Peguino OLED96 brick is connected
//#include "OLEDPEGULOGO_01.h" // contains the Peguino Logo as XBM file.
#define Microprox_Left 36 // Analog Input from GPIO 36 which is physically located on Pin 17 and available on Port C3 where the left Microprox Brick is connected
#define Microprox_Right 32 // Analog Input from GPIO 32 which is physically located on Pin 21 and available on Port D1 where the right Microprox Brick is connected
int valueLeft = 0;
int valueRight = 0;
int gochart = 0; // indicator for switch button in Serial Plotter
const int LEFT_SERVO = 27; // GPIO Pin for the left wheel / Peguino 360Deg. Microservo
const int RIGHT_SERVO = 33; // GPIO Pin for the right wheel / Peguino 360Deg. Microservo
char * ssid = "PeguinoBot1"; // The Peguino Bot SSID
char * password = "peguinobot1"; // The WIFI Password
int buttonPin = 25; // Port D2 (Pin 23 GPIO25) connects the Button Brick
int buttonState = LOW; // variable for reading the Button Brick status
int drivestatus = 0; // do the robot's wheels spinning?
int ledPinR = 13; // red RGB LED Brick
int ledPinG = 12; // green RGB LED Brick
int ledPinB = 14; // blue RGB LED Brick
int ledChannelR = 13;
int ledChannelG = 12;
int ledChannelB = 14;
int LEDfreq = 500;
int val = -1;
int servoSpeed = 25;
int servoSpeedLeft = 49;
String showiptext = "Pegubot IP: ";
String showip = " ";
int servoSpeedRight = 51;
int trigPin = 2; // Trigger Signal for the Peguino Proximity Brick
int echoPin = 15; // Echo Signal for the Peguino Proximity Brick
long duration, cm;
int freq = 440; // the initial audio frequency in Hz for the Peguino Buzzer Brick
int whizchannel = 2; // ESP32 speciality
int resolution = 8; // ESP32 speciality - it means 8 Bits resolution to count from 0 - 255
int whizzer = 0; // the counter of whizz sound cycles
int whizz = 0; // the sound frequency we use
int reverseonly = 0; // is used to allow only to dive backwards in case a potential collision could be detected by the Proximity Brick
int nowdriving = 0; // is used to memorize that we drive right now....
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(500);
Serial.println("Start");
Serial.setDebugOutput(true);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
initServos(); // Initialise the Peguino 360Deg. Microservos
// Wireless
Serial.print("Creating Access Point");
WiFi.softAPdisconnect();
WiFi.mode(WIFI_MODE_AP);
while (!WiFi.softAP(ssid, password)) {
Serial.print(".");
}
Serial.println("");
Serial.println("Network Created!");
Serial.print("PeguinoBot IP address = ");
Serial.println(WiFi.softAPIP());
// Webserver
Serial.print("Creating HTTP Server");
server.begin();
WiFi.printDiag(Serial);
// Buzzer Brick
ledcSetup(whizchannel, freq, resolution); //ESP32 speciality - PWM function to control the Buzzer Brick
ledcAttachPin(23, whizchannel); //ESP32 speciality - attach it at Pin23
display.clear(); // clean screen
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
showip = String(showiptext + WiFi.softAPIP().toString());
display.drawStringMaxWidth(0, 0, 128, showip);
display.display();
Serial.println(showip);
// RGB LED Brick
ledcSetup(ledChannelR, LEDfreq, resolution);
ledcAttachPin(ledPinR, ledChannelR);
ledcSetup(ledChannelG, LEDfreq, resolution);
ledcAttachPin(ledPinG, ledChannelG);
ledcSetup(ledChannelB, LEDfreq, resolution);
ledcAttachPin(ledPinB, ledChannelB);
ledcWrite(ledChannelR, 255); // 255 = LED off, 0 = LED maximal brightness!
ledcWrite(ledChannelG, 255);
ledcWrite(ledChannelB, 255);
// Button Brick
pinMode(buttonPin, INPUT); // initialize the Button Brick pin as an input
ledcWrite(ledChannelR, 0);
ledcWrite(ledChannelG, 255);
ledcWrite(ledChannelB, 255);
}
// -------------------------------
void loop() {
WiFiClient client = server.available();
if (client) {
// we have a new client sending some request
String req = client.readStringUntil('\r');
Serial.println(req);
String response = processRequest(req);
while (client.connected()) {
if (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
if (line.length() == 1 && line[0] == '\n') {
client.println(prepareHtmlPage(response));
break;
}
}
}
delay(1); // give the web browser time to receive the data
// close the connection:
client.stop();
Serial.println("[Client disonnected]");
}
buttonState = digitalRead(buttonPin); // read the state of the Button Brick
// now check if the Bbutton brick is pressed. If it is, the buttonState is HIGH:
if (buttonState != HIGH) {
} else {
ledcWrite(ledChannelR, 255);
ledcWrite(ledChannelG, 255);
ledcWrite(ledChannelB, 0);
delay (750); // if you remove the 0.75 seconds waiting time you can see the bouncing spikes interfering the results
if (drivestatus == 7)
{
drivestatus = 4; // Stop
ledcWrite(ledChannelR, 0);
ledcWrite(ledChannelG, 255);
ledcWrite(ledChannelB, 255);
}
else
{
drivestatus = 7; // Start Linetracking
// val = -7;
reverseonly = 0;
ledcWrite(ledChannelR, 255);
ledcWrite(ledChannelG, 0);
ledcWrite(ledChannelB, 255);
whizzer = 0; // Startsound
}
}
// Microprox reading
valueLeft = analogRead(Microprox_Left);
valueRight = analogRead(Microprox_Right);
// Proximity sensor
// The sensor triggers by a HIGH pulse of 10 or more microseconds - a short LOW pulse first ensures a clean HIGH pulse:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Signal readout: The HIGH pulse duration is the time (in microseconds) from sending ping to receiving the echo bumping from an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// Convert time of flight to distance
cm = (duration / 2) / 29.1; // Divide by 29.1 for cm and 74 for inches
//Serial.print(cm * 2.2); // Multiply by 2.2 to get a nice chart ....
//Serial.print(",");
char valueLeft_str[16];
itoa(valueLeft, valueLeft_str, 10); // converts integer number to string
char valueRight_str[16];
itoa(valueRight, valueRight_str, 10); // converts integer number to string
if (cm > 50) { cm = 50;} // everything above 50cm creates useless values for us here
char cm_str[16];
itoa(cm, cm_str, 10); // converts integer number to string
display.clear(); // clear the Peguino OLED96 display
display.drawStringMaxWidth(0, 0, 128, showip);
display.drawStringMaxWidth(0, 10, 128, cm_str );
display.drawStringMaxWidth(10, 10, 128, " cm");
display.drawStringMaxWidth(0, 40, 128, valueLeft_str );
display.drawStringMaxWidth(102, 40, 128, valueRight_str );
if (cm <= 5 && reverseonly == 0) {
// String response = processRequest("/servo/stop"); // BRAKE!!! Stop driving to avoid collision
display.drawStringMaxWidth(44, 10, 128, "OBSTACLE!");
ledcWrite(ledChannelR, 0);
ledcWrite(ledChannelG, 255);
ledcWrite(ledChannelB, 255);
// if (drivestatus != 7) {reverseonly = 1;} // assumed we started somehow remote controlled
// if (drivestatus == 7) {drivestatus = 4;} // assumed we started as a linefinder and something is in front of us and lets as stop driving
}
// show the Microprox Sensors
if (valueLeft > 3900) // black line is above 3900 - max is 4095
{display.drawStringMaxWidth(0, 50, 128, "BLACK" );}
if (valueRight > 3900) // black line is above 3900 - max is 4095
{display.drawStringMaxWidth(94, 50, 128, "BLACK" );}
// START DRIVE INFO (and some basic behaviour logic...)
if ((val == -2) || drivestatus == 2 && reverseonly == 0) // allows driving forward only if there is nothing in front of the Proximity Brick
{ display.drawStringMaxWidth(36 ,20, 128, "FORWARD"); drivestatus = 2; nowdriving = 1;}
if ((val == -5) || drivestatus == 2 && reverseonly == 1 && nowdriving == 1)
{ display.drawStringMaxWidth(36, 20, 128, "REVERSE"); drivestatus = 3; nowdriving = 0; reverseonly = 0; } // allows only to drive backwards in case something is in front of the Proximity Brick
if ((val == -3) || drivestatus == 3)
{ display.drawStringMaxWidth(36, 20, 128, "REVERSE"); drivestatus = 3; }
/* if ((val == -4) || drivestatus == 4)
{ display.drawStringMaxWidth(44, 20, 128, "STOPPED"); drivestatus = 4; } */
if ((val == -5) || drivestatus == 5)
{ display.drawStringMaxWidth(30, 20, 128, "TURN LEFT"); drivestatus = 5; }
if ((val == -6) || drivestatus == 6)
{ display.drawStringMaxWidth(30, 20, 128, "TURN RIGHT"); drivestatus = 6; }
if ((val == -7) || drivestatus == 7 && reverseonly == 0)
{
display.drawStringMaxWidth(22, 20, 128, "FOLLOW LINE"); drivestatus = 7; nowdriving = 1;
}
if (drivestatus == 4){
//display.clear();
display.drawStringMaxWidth(22, 20, 128, "Button STOP");
servoWrite(0, 54); // left stop
servoWrite(1, 50); // right stop
ledcWrite(ledChannelR, 0);
ledcWrite(ledChannelG, 255);
ledcWrite(ledChannelB, 255);
}
if ((valueLeft > 3900) && (valueRight > 3900) && (drivestatus == 7))
{
// both Microprox sensors triggering, better to stop now...
// String response = processRequest("/servo/stop"); // BRAKE!!! Stop driving to avoid collision
display.drawStringMaxWidth(44, 10, 128, "2 BLACKS!");
servoWrite(0, 54); // left stop
servoWrite(1, 50); // right stop
ledcWrite(ledChannelR, 0);
ledcWrite(ledChannelG, 255);
ledcWrite(ledChannelB, 255);
// if (drivestatus != 7) {reverseonly = 1;} // assumed we started somehow remote controlled
drivestatus = 4; // assumed we started as a linefinder and something is in front of us and lets as stop driving
}
else {
if ((valueLeft > 3900) && (drivestatus == 7)) // black line is above 3900 - max is 4095
{
display.drawStringMaxWidth(0, 50, 128, "BLACK" );
// stop the left wheel, assume the right is still spinning it turns the driving bot to the left
servoWrite(0, 54); // 54 slow down the right wheel
servoWrite(1, 54); // 54
//String response = processRequest("/servo/stop"); // BRAKE!!! Stop driving to avoid collision
ledcWrite(ledChannelR, 255);
ledcWrite(ledChannelG, 0);
ledcWrite(ledChannelB, 128);
}
else if ((valueRight > 3900) && (drivestatus == 7)) // black line is above 3900 - max is 4095
{
display.drawStringMaxWidth(94, 50, 128, "BLACK" );
// stop the right wheel, assume the right is still spinning it turns the driving bot to the left
servoWrite(0, 58); // 59
servoWrite(1, 51); // 50 slow down the left wheel
ledcWrite(ledChannelR, 128);
ledcWrite(ledChannelG, 0);
ledcWrite(ledChannelB, 255);
}
else if (drivestatus == 7)
{
// everything is fine - keep going
servoWrite(0, 57); // 59 right wheel 90 full speed, 56 halt range of 34 half 17; 90 82 75 68 62 58 || 50 or 54 = stop
servoWrite(1, 53); // 54 left wheel (drive direction)
ledcWrite(ledChannelR, 255);
ledcWrite(ledChannelG, 0);
ledcWrite(ledChannelB, 255);
}
}
// STOP DRIVE INFO
display.display(); // (re)draw the Peguino OLED96 display
// process Microprox input
//Serial.print(valueLeft); // the Left Microprox for plotting
//Serial.print(","); // seperator
//Serial.print(valueRight); // the right Microprox for plotting
//Serial.print(",");
//Serial.println(gochart); // the start button (low and high)
//delay(5);
// Buzzer Brick stuff
while (whizz <= 3) {
whizz += 1;
for (int freq = 440; freq <= 2000; freq = freq + 30) {
ledcWriteTone(whizchannel, freq);
delay(5);
}
whizzer += 1;
}
if (whizzer == 4) {
ledcWriteTone(whizchannel, -1); //ESP32 speciality - turn off sound
}
}
// process wifi input
String processRequest(String req) {
// int val = -1;
if (req.indexOf("/led/0") != -1) {
val = 0;
} else if (req.indexOf("/led/1") != -1) {
val = 1;
} else if (req.indexOf("/servo/forward") != -1) {
val = -2;
} else if (req.indexOf("/servo/reverse") != -1) {
val = -3;
} else if (req.indexOf("/servo/stop") != -1) {
val = -4;
} else if (req.indexOf("/servo/turnleft") != -1) {
val = -5;
} else if (req.indexOf("/servo/turnright") != -1) {
val = -6;
} else if (req.indexOf("/servo/follow") != -1) {
val = -7;
}
if (val >= 0) {
return "nope";
} else {
switch (val) {
case -1:
return "<h2>Peguino Bot Remote Control</h2><br/><table class='buttons' cellpadding='10'><tr><td colspan='3'><a href='/servo/follow'> FORWARD AND FOLLOW A BLACK LINE</a></td></tr><tr><td> </td><td><a href='/servo/forward'> FORWARD </a></td><td> </td></tr><tr><td><a href='/servo/turnleft'> TURN LEFT </a></td><td align='center'><a href='/servo/stop'> STOP </a></td><td><a href='/servo/turnright'> TURN RIGHT </a></td></tr><tr><td> </td><td><a href='/servo/reverse'> REVERSE </a></td><td> </td></tr></table>";
break;
case -2: // forward
servoWrite(0, 90);
servoWrite(1, 90);
return "<h2>Peguino Bot Remote Control</h2><br/><table class='buttons' cellpadding='10'><tr><td colspan='3'><a href='/servo/follow'> FORWARD AND FOLLOW A BLACK LINE</a></td></tr><tr><td> </td><td><a href='/servo/forward'> FORWARD </a></td><td> </td></tr><tr><td><a href='/servo/turnleft'> TURN LEFT </a></td><td align='center'><a href='/servo/stop'> STOP </a></td><td><a href='/servo/turnright'> TURN RIGHT </a></td></tr><tr><td> </td><td><a href='/servo/reverse'> REVERSE </a></td><td> </td></tr></table>";
break;
case -3: // reverse
servoWrite(0, 10); // 0
servoWrite(1, 10); // 20
return "<h2>Peguino Bot Remote Control</h2><br/><table class='buttons' cellpadding='10'><tr><td colspan='3'><a href='/servo/follow'> FORWARD AND FOLLOW A BLACK LINE</a></td></tr><tr><td> </td><td><a href='/servo/forward'> FORWARD </a></td><td> </td></tr><tr><td><a href='/servo/turnleft'> TURN LEFT </a></td><td align='center'><a href='/servo/stop'> STOP </a></td><td><a href='/servo/turnright'> TURN RIGHT </a></td></tr><tr><td> </td><td><a href='/servo/reverse'> REVERSE </a></td><td> </td></tr></table>";
break;
case -4: // stop
servoWrite(0, 54); // left
servoWrite(1, 50); // right
return "<h2>Peguino Bot Remote Control</h2><br/><table class='buttons' cellpadding='10'><tr><td colspan='3'><a href='/servo/follow'> FORWARD AND FOLLOW A BLACK LINE</a></td></tr><tr><td> </td><td><a href='/servo/forward'> FORWARD </a></td><td> </td></tr><tr><td><a href='/servo/turnleft'> TURN LEFT </a></td><td align='center'><a href='/servo/stop'> STOP </a></td><td><a href='/servo/turnright'> TURN RIGHT </a></td></tr><tr><td> </td><td><a href='/servo/reverse'> REVERSE </a></td><td> </td></tr></table>";
break;
case -5: // turn left
servoWrite(0, 75);
servoWrite(1, 56);
return "<h2>Peguino Bot Remote Control</h2><br/><table class='buttons' cellpadding='10'><tr><td colspan='3'><a href='/servo/follow'> FORWARD AND FOLLOW A BLACK LINE</a></td></tr><tr><td> </td><td><a href='/servo/forward'> FORWARD </a></td><td> </td></tr><tr><td><a href='/servo/turnleft'> TURN LEFT </a></td><td align='center'><a href='/servo/stop'> STOP </a></td><td><a href='/servo/turnright'> TURN RIGHT </a></td></tr><tr><td> </td><td><a href='/servo/reverse'> REVERSE </a></td><td> </td></tr></table>";
break;
case -6: // turn right
servoWrite(0, 56);
servoWrite(1, 75);
return "<h2>Peguino Bot Remote Control</h2><br/><table class='buttons' cellpadding='10'><tr><td colspan='3'><a href='/servo/follow'> FORWARD AND FOLLOW A BLACK LINE</a></td></tr><tr><td> </td><td><a href='/servo/forward'> FORWARD </a></td><td> </td></tr><tr><td><a href='/servo/turnleft'> TURN LEFT </a></td><td align='center'><a href='/servo/stop'> STOP </a></td><td><a href='/servo/turnright'> TURN RIGHT </a></td></tr><tr><td> </td><td><a href='/servo/reverse'> REVERSE </a></td><td> </td></tr></table>";
break;
case -7: // forward and follow the line
servoWrite(0, 90);
servoWrite(1, 90);
return "<h2>Peguino Bot Remote Control</h2><br/><table class='buttons' cellpadding='10'><tr><td colspan='3'><a href='/servo/follow'><i> FORWARD AND FOLLOW A BLACK LINE </i></a></td></tr><tr><td> </td><td><a href='/servo/forward'> FORWARD </a></td><td> </td></tr><tr><td><a href='/servo/turnleft'> TURN LEFT </a></td><td align='center'><a href='/servo/stop'> STOP </a></td><td><a href='/servo/turnright'> TURN RIGHT </a></td></tr><tr><td> </td><td><a href='/servo/reverse'> REVERSE </a></td><td> </td></tr></table>";
break;
}
}
return "Something went wrong";
}
String prepareHtmlPage(String output) {
String htmlPage =
String("HTTP/1.1 200 OK\r\n") +
"Content-Type: text/html\r\n" +
"Connection: close\r\n" + // the connection will be closed after completion of the response
"\r\n" +
"<!DOCTYPE HTML>" +
"<html><style>html {color: black; font-family: sans-serif;} .buttons {border: 2px red solid;} .buttons td {border: 2px red solid; background-color: #9ceeff; padding-top: 25px; padding-bottom: 25px} a, a.visited { color: black; font-weight: bold; text-decoration: none;} </style><body>" +
output +
"</body></html>" +
"\r\n";
return htmlPage;
}
void initServos() {
ledcSetup(0, 50, 16); // channel 0, 50 Hz, 16-bit depth because my servos do not stop on the same position thez are changed to 51 and 49!!!
ledcAttachPin(LEFT_SERVO , 0);
ledcSetup(1, 50, 16); // channel 1, 50 Hz, 16-bit depth
ledcAttachPin(RIGHT_SERVO , 1);
}
void servoWrite(int channel, int dutyPercent) {
int pulse = map(((channel == 0) ? 104 - dutyPercent : dutyPercent), 0, 100, 1500, 8000);
ledcWrite(channel, pulse);
// Serial.print("Wrote "); Serial.print(pulse); Serial.print(" to Servo "); Serial.println(channel);
}
Images
![[Image: Peguinobot_01.jpg]](https://www.peguino.com/chat/images/Peguinobot_01.jpg)
|
|
|
Peguino Gyrosensor Brick |
Posted by: Peguinohero - 01-10-2019, 01:29 PM - Forum: Alle Peguino Bricks und deren Beschreibungen etc.
- No Replies
|
 |
Peguino Gyrosensor Brick
Dieser Peguino Baustein beinhaltet einen Gyroskopsensor. Mit ihm können Bewegungen registriert und gemessen werden und dabei werden Informationen wie die Position im Raum, die Beschleunigung und den dreidimensionalen Winkel des Bausteins zur verfügung gestellt.
Bild derzeit noch nicht verfübgar...
Hinweis: Dieser Baustein kommuniziert mit dem Peguino Uno Brick über das I2C Kommunikationsprotokoll. Da jeder I2C-Baustein wie er in dem Display verwendet wird eine eigene Adresse haben kann muss diese zunächst ermittelt werden. Hierfür kann der "I2C Adressscanner" in den Programmscripten unten verwendet werden. Mit diesem Skript wird die Adresse des Displays ermittelt. Diese Adresse wird für das zweite Programmscript unten benötigt und muss dort an entsprechender Stelle eingefügt werden.weitere
Weitere Informationen derzeit in Vorbereitung...
Examples for Peguino Uno Nano and ESP32 V1:
Code: /*
Gyrosensor Brick
(C) 2018 by Peguino LTD
Version 0.3
Note: Use the Serial Monitor to see the Data
Connect a Peguino Microservo Brick on Port C1
Peguino Uno Nano Board Pinout Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐ ┌─╥─┐
D_13 1 │ │ 30 D_12 3.3 1 │ │ 30 5V
3.3 V 2 │ │ 29 D_11 GND 2 │ │ 29 GND
AREF 3 │ │ 28 D_10 GPIO15 3 │ │ 28 GPIO13
D_14 A_0 4 │ │ 27 D_9 GPIO2 4 │ │ 27 GPIO12
D_15 A_1 5 │ │ 26 D_8 GPIO4 5 │ │ 26 GPIO14
D_16 A_2 6 │ │ 25 D_7 GPIO16 6 │ │ 25 GPIO27
D_17 A_3 7 │ │ 24 D_6 GPIO17 7 │ │ 24 GPIO26
D_18 A_4 8 │ │ 23 D_5 GPIO5 8 │ │ 23 GPIO25
D_19 A_5 9 │ │ 22 D_4 GPIO18 9 │ │ 22 GPIO33
A_6 10 │ │ 21 D_3 GPIO19 10 │ │ 21 GPIO32
A_7 11 │ │ 20 D_2 GPIO21 11 │ │ 20 GPIO35
5V 12 │ │ 19 GND GPIO3 12 │ │ 19 GPIO34
Reset 13 │ │ 18 Reset GPIO1 13 │ │ 18 GPIO39
GND 14 │ │ 17 D_0 RX GPIO22 14 │ │ 17 GPIO36
Power In 15 │ │ 16 D_1 TX GPIO23 15 │ │ 16 Chip enable
└───┘ └───┘
Visit https://www.peguino.com
*/
#include<Wire.h>
#include <math.h>
//#include <ESP32Servo.h> // for ESP32 Development Board V1
#include <Servo.h> // for Arduino Nano
const int MPU = 0x68; // Default I2C address for this Brick
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
double pitch, roll;
Servo servo1;
Servo servo2;
int minUs = 500;
int maxUs = 2400;
int servo1Pin = 5;
int pos1 = 0;
int servoangle01 = 950;
int servoangle02 = 0;
int servoangle02a = 0;
int servoangle02b = 0;
int servoangle02c = 0;
int servoangle02d = 0;
int servoangle02e = 0;
int servoangle03 = 0;
void setup() {
Serial.begin(9600);
Serial.println("Peguino Gyrosensor");
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
servo1.attach(servo1Pin, minUs, maxUs); // In this example we use Port C1
}
void loop() {
Wire.beginTransmission(MPU);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU, 14, true);
int AcXoff, AcYoff, AcZoff, GyXoff, GyYoff, GyZoff;
int temp, toff;
double t, tx, tf;
//Acceleration data correction
AcXoff = -950;
AcYoff = -300;
AcZoff = 0;
//Temperature correction
toff = -1600;
//Gyro correction
GyXoff = 480;
GyYoff = 170;
GyZoff = 210;
//read accel data
AcX = (Wire.read() << 8 | Wire.read()) + AcXoff;
AcY = (Wire.read() << 8 | Wire.read()) + AcYoff;
AcZ = (Wire.read() << 8 | Wire.read()) + AcYoff;
//read temperature data
temp = (Wire.read() << 8 | Wire.read()) + toff;
tx = temp;
t = tx / 340 + 36.53;
tf = (t * 9 / 5) + 32;
//read gyro data
GyX = (Wire.read() << 8 | Wire.read()) + GyXoff;
GyY = (Wire.read() << 8 | Wire.read()) + GyYoff;
GyZ = (Wire.read() << 8 | Wire.read()) + GyZoff;
//get pitch/roll
getAngle(AcX, AcY, AcZ);
servoangle02 = ((((AcY / 10) / 1.72631) + servoangle01) + 550); // funny range calculation to match the servo
servoangle02e = servoangle02d;
servoangle02d = servoangle02c;
servoangle02c = servoangle02b;
servoangle02b = servoangle02a;
servoangle02a = servoangle02;
servoangle03 = (servoangle02 + servoangle02a + servoangle02b + servoangle02c + servoangle02d + servoangle02e) / 6;
if (servoangle03 < 550)
{ servoangle03 = 550;
}
if (servoangle03 > 2400)
{ servoangle03 = 2400;
}
Serial.print("a: ");
Serial.print(servoangle02);
Serial.print(", ");
Serial.print("b: ");
Serial.println(servoangle03);
servo1.write(servoangle03);
delay(50);
}
void getAngle(int Vx, int Vy, int Vz) {
double x = Vx;
double y = Vy;
double z = Vz;
}
|
|
|
Peguino LCD Display Brick |
Posted by: Peguinohero - 01-10-2019, 12:26 PM - Forum: Alle Peguino Bricks und deren Beschreibungen etc.
- No Replies
|
 |
Peguino LCD Display Brick
Dieser Peguino Baustein beinhaltet ein zweizeiliges Textdisplay. Mit diesem Baustein können vielerlei unterscheidliche Projekte realisiert werden. Z.B. kann hiermit die Temperatur des Peguino Climate Brick angezeigt werden.
![[Image: LCD_Display_brick_01b.png]](https://www.peguino.com/chat/images/LCD_Display_brick_01b.png)
Hinweis: Dieser Baustein kommuniziert mit dem Peguino Uno Brick über das I2C Kommunikationsprotokoll. Da jeder I2C-Baustein wie er in dem Display verwendet wird eine eigene Adresse haben kann muss diese zunächst ermittelt werden. Hierfür kann der "I2C Adressscanner" in den Programmscripten unten verwendet werden. Mit diesem Skript wird die Adresse des Displays ermittelt. Diese Adresse wird für das zweite Programmscript unten benötigt und muss dort an entsprechender Stelle eingefügt werden.
Beispiel für Peguino Uno Nano und Peguino Uno ESP32 V1:
Um die korrekte I2C Adresse zu ermitteln muss das OLED Display mit dem Port B verbunden werden. Dieses Programm ist für den Peguino Uni Nano und Peguino Uno ESP32 identisch.
I2C Adressscanner
Kopiere das Programmskript unten (CTRL+C) und füge es in die Arduino IDE ein (CTRL+V). Kompiliere und übertrage das fertige Programm mit der Arduino IDE auf das Peguino Uno Board.
Kopiere die mit dem Adressscanner ermittelte Adresse anshließend in das zweite Codebeispiel unten.
Code: /*
I2C Address Scanner
(C) 2018 by Peguino LTD
Connect the Brick to scan to port B (eg. OLED Display Brick or LCD Display Brick...)
Version 1
Note: Use the Serial Monitor to see the found Address
Peguino Uno Nano Board Pinout Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐ ┌─╥─┐
D_13 1 │ │ 30 D_12 3.3 1 │ │ 30 5V
3.3 V 2 │ │ 29 D_11 GND 2 │ │ 29 GND
AREF 3 │ │ 28 D_10 GPIO15 3 │ │ 28 GPIO13
D_14 A_0 4 │ │ 27 D_9 GPIO2 4 │ │ 27 GPIO12
D_15 A_1 5 │ │ 26 D_8 GPIO4 5 │ │ 26 GPIO14
D_16 A_2 6 │ │ 25 D_7 GPIO16 6 │ │ 25 GPIO27
D_17 A_3 7 │ │ 24 D_6 GPIO17 7 │ │ 24 GPIO26
D_18 A_4 8 │ │ 23 D_5 GPIO5 8 │ │ 23 GPIO25
D_19 A_5 9 │ │ 22 D_4 GPIO18 9 │ │ 22 GPIO33
A_6 10 │ │ 21 D_3 GPIO19 10 │ │ 21 GPIO32
A_7 11 │ │ 20 D_2 GPIO21 11 │ │ 20 GPIO35
5V 12 │ │ 19 GND GPIO3 12 │ │ 19 GPIO34
Reset 13 │ │ 18 Reset GPIO1 13 │ │ 18 GPIO39
GND 14 │ │ 17 D_0 RX GPIO22 14 │ │ 17 GPIO36
Power In 15 │ │ 16 D_1 TX GPIO23 15 │ │ 16 Chip enable
└───┘ └───┘
Visit https://www.peguino.com
*/
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin (115200); // Press Ctrl+Shift+M and set the serial monitor to the same baud rate!
Serial.println("Peguino I2C OLED Display Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("OLED Display found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(500);
}
Im Serial Monitor der Arduino IDE wird nun die Adresse angezeigt (siehe Beispiel unten):
![[Image: LCDDisplay_scanadress_01.png]](https://www.peguino.com/chat/images/LCDDisplay_scanadress_01.png)
Füge die Adresse (im Beispiel oben lautet die Adresse 0x27) in das Programmscript aus dem Beispiel unten an entsprechender Stelle ein...
Für das Peguino LCD Display wird eine spezielle Funktionsbibliothek benötigt. Diese kann in die Arduino IDE mit folgenden Schritten eingefügt werden.
1. Drücken und halten der Tasten CTRL + Hochstellen + I um den " Library Manager" zu öffnen.
2. Tippe "LiquidCrystal_I2C" in das Eingabe-Suchfeld ein und wähle dann "LiquidCrystal I2C library by Franz de Brabander" aus. Mit einem Klick auf "Install" wird die Funktionsbibliothek installiert.
Kopiere das Programmskript unten (CTRL+C) und füge es in die Arduino IDE ein (CTRL+V). Kompiliere und übertrage das fertige Programm mit der Arduino IDE auf das Peguino Uno Board.
Code: /*
LCD Display Brick
(C) 2018 by Peguino LTD
Connect the LED Display Display Brick to port B
Version 1
Note: Check the I2C Address Scanner script first to get the correct I2C Address
Peguino Uno Nano Board Pinout Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐ ┌─╥─┐
D_13 1 │ │ 30 D_12 3.3 1 │ │ 30 5V
3.3 V 2 │ │ 29 D_11 GND 2 │ │ 29 GND
AREF 3 │ │ 28 D_10 GPIO15 3 │ │ 28 GPIO13
D_14 A_0 4 │ │ 27 D_9 GPIO2 4 │ │ 27 GPIO12
D_15 A_1 5 │ │ 26 D_8 GPIO4 5 │ │ 26 GPIO14
D_16 A_2 6 │ │ 25 D_7 GPIO16 6 │ │ 25 GPIO27
D_17 A_3 7 │ │ 24 D_6 GPIO17 7 │ │ 24 GPIO26
D_18 A_4 8 │ │ 23 D_5 GPIO5 8 │ │ 23 GPIO25
D_19 A_5 9 │ │ 22 D_4 GPIO18 9 │ │ 22 GPIO33
A_6 10 │ │ 21 D_3 GPIO19 10 │ │ 21 GPIO32
A_7 11 │ │ 20 D_2 GPIO21 11 │ │ 20 GPIO35
5V 12 │ │ 19 GND GPIO3 12 │ │ 19 GPIO34
Reset 13 │ │ 18 Reset GPIO1 13 │ │ 18 GPIO39
GND 14 │ │ 17 D_0 RX GPIO22 14 │ │ 17 GPIO36
Power In 15 │ │ 16 D_1 TX GPIO23 15 │ │ 16 Chip enable
└───┘ └───┘
Visit https://www.peguino.com
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // copy here the correct address in here. Replace the 0x27 with the Address your scan has provided!
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight();
lcd.setCursor(0,0); // 0,0 = start with the first character at first line (counting starts with zero!)
lcd.print("PEGUINO LCD");
lcd.setCursor(0,1); // 0,1 = start with the first character at the second line (counting starts with zero!)
lcd.print("Display Brick");
}
void loop()
{
}
|
|
|
Peguino Climate Brick |
Posted by: Peguinohero - 01-10-2019, 10:27 AM - Forum: Alle Peguino Bricks und deren Beschreibungen etc.
- No Replies
|
 |
Peguino Climate Brick
Dieser Peguino Baustein beinhaltet einen Temperatur- und Luftfeuchtigkeitssensor. Damit lässt sich beispielsweise eine Wetterstation bauen oder die Temperatur und Luftfeuchtigkeit eines Gewächshauses ermitteln. Als Sensor kommt ein hochpräziser DHT22 Sensor zum Einsatz, der Temperaturen im Bereich zwischen -40º bis +80º Celsius bei einer relativen Luftfeuchtigkeit von 0 bis 100% misst.
![[Image: Brick_Climate_01b.png]](https://www.peguino.com/chat/images/Brick_Climate_01b.png)
Beispiel für Peguino Uno Nano und Peguino Uno ESP32 V1:
Stecke den Peguino Climate Brick an den Steckverbinder D3 an einen Peguino Uno Nano Brick. (Achtung: Das schwarze Kabel muss dabei immer unten sein)
Für die Nutzer eines Peguino Uno ESP32 muss der Climate Brick an den Steckverbinder D1 gesteckt werden. (schwarzes Kabel ebenfalls immer unten)
1a. Beispiel für Peguino Uno Nano:
Für den Climate Brick wird eine spezielle Funktionsbibliothek benötigt. Diese kann in die Arduino IDE mit folgenden Schritten eingefügt werden.
1. Drücken und halten der Tasten CTRL + Hochstellen + I um den " Library Manager" zu öffnen.
2. Tippe "SimpleDHT" in das Eingabe-Suchfeld ein und wähle dann "SimpleDHT" aus. Mit einem Klick auf "Install" wird die Funktionsbibliothek installiert.
Kopiere das Programmskript unten (CTRL+C) und füge es in die Arduino IDE ein (CTRL+V). Kompiliere und übertrage das fertige Programm mit der Arduino IDE auf das Peguino Uno Board.
1b. Programmskript für einen Peguino Uno Nano Baustein:
Code: /*
Climate Brick
(C) 2018 by Peguino LTD
Connect the Climate Brick to port D3
Version 1
Note: Use the Serial Monitor or Plotter to see the values // Press Ctrl+Shift+L or // Press Ctrl+Shift+M
The Climate Brick contains a DHT-22 sensor module
Peguino Uno Nano Board Pinout
┌─╥─┐
D_13 1 │ │ 30 D_12
3.3 V 2 │ │ 29 D_11
AREF 3 │ │ 28 D_10
D_14 A_0 4 │ │ 27 D_9
D_15 A_1 5 │ │ 26 D_8
D_16 A_2 6 │ │ 25 D_7
D_17 A_3 7 │ │ 24 D_6
D_18 A_4 8 │ │ 23 D_5
D_19 A_5 9 │ │ 22 D_4
A_6 10 │ │ 21 D_3
A_7 11 │ │ 20 D_2
5V 12 │ │ 19 GND
Reset 13 │ │ 18 Reset
GND 14 │ │ 17 D_0 RX
Power In 15 │ │ 16 D_1 TX
└───┘
Visit https://www.peguino.com
*/
#include <SimpleDHT.h> // needed Library
SimpleDHT22 dht22(6); // The sensor communicates via the Digital Pin 6 of the Arduino Nano / Connector D3
void setup()
{
Serial.begin(115200); // Press Ctrl+Shift+L and set the serial monitor to the same baud rate!
}
void loop()
{
float temperature = 0;
float humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht22.read2(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Read DHT22 failed, err="); Serial.println(err);delay(2000);
return;
}
Serial.print("Humidity: ");
Serial.print((float)humidity);
Serial.print(" %, Temp: ");
Serial.print((float)temperature);
Serial.println(" Celsius");
delay(1000);
}
2a. Beispiel für Peguino Uno ESP32 V1:
Für den Climate Brick wird eine spezielle auf den ESP32 angepasste Funktionsbibliothek benötigt. Diese kann in die Arduino IDE mit folgenden Schritten eingefügt werden.
1. Drücken und halten der Tasten CTRL + Hochstellen + I um den " Library Manager" zu öffnen.
2. Tippe "DHT22" in das Eingabe-Suchfeld ein und wähle dann "DHT sensor library for ESPx" aus. Mit einem Klick auf "Install" wird die Funktionsbibliothek installiert.
Kopiere das Programmskript unten (CTRL+C) und füge es in die Arduino IDE ein (CTRL+V). Kompiliere und übertrage das fertige Programm mit der Arduino IDE auf das Peguino Uno Board.
2. Programmskript für einen Peguino Uno ESP32 Baustein:
Code: /*
Climate Brick
(C) 2018 by Peguino LTD
Connect the Climate Brick to port D1
Version 1
Note: Use the Serial Monitor or Plotter to see the values Press Ctrl+Shift+L or press Ctrl+Shift+M
The Climate Brick contains a DHT-22 sensor module
Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐
3.3 1 │ │ 30 5V
GND 2 │ │ 29 GND
GPIO15 3 │ │ 28 GPIO13
GPIO2 4 │ │ 27 GPIO12
GPIO4 5 │ │ 26 GPIO14
GPIO16 6 │ │ 25 GPIO27
GPIO17 7 │ │ 24 GPIO26
GPIO5 8 │ │ 23 GPIO25
GPIO18 9 │ │ 22 GPIO33
GPIO19 10 │ │ 21 GPIO32
GPIO21 11 │ │ 20 GPIO35
GPIO3 12 │ │ 19 GPIO34
GPIO1 13 │ │ 18 GPIO39
GPIO22 14 │ │ 17 GPIO36
GPIO23 15 │ │ 16 Chip enable
└───┘
Visit https://www.peguino.com
*/
#include "DHTesp.h" // needed Library
DHTesp dht;
void setup()
{
Serial.begin(115200); // Press Ctrl+Shift+L and set the serial monitor to the same baud rate!
dht.setup(26, DHTesp::DHT22); // The DHT22-sensor "Data" is connected to GPIO 26 which is physically located on Pin 24 and available on Port D1
}
void loop()
{
float temp = dht.getTemperature();
float hum = dht.getHumidity();
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(1000);
}
Ausgabefenster des "Serial Monitor" der Arduino IDE:
Zum öffnen Ctrl+Hochstellentaste+L drücken...
|
|
|
Peguino Body Sensor Brick (Bewegungssensor) |
Posted by: Peguinohero - 01-09-2019, 07:52 PM - Forum: Alle Peguino Bricks und deren Beschreibungen etc.
- No Replies
|
 |
Peguino Body Sensor Brick (Bewegungssensor)
Dieser Peguino Baustein beinhaltet einen passiven Infrarotsensor. Mit ihm kann die Bewegung von Personen registriert werden und z.B. für eine automatische Begrüßungsfunktion genutzt werden wenn sich jemand in die Nähe des Sensors bewegt.
![[Image: Brick_Bodysensor_01b.png]](https://www.peguino.com/chat/images/Brick_Bodysensor_01b.png)
Anmerkung: Der Body Sensor Brick hat zwei interne Potentiometer zur Einstellung der Charakteristika des Sensors. Diese können mit einem kleinen Schraubendreher justiert werden. Es kann die Verzögerungszeit und der Sensor-Bereich eingestellt werden. Werden beide ganz nach links gedreht befindet sich der Sensor in der Grundeinstellung.
Charakteristik des Sensors:
Wird das Projekt mit Strom verbunden benötigt der Sensor bis zu einer Minute um korrekt zu arbeiten. In dieser Zeit kann der Sensor falsche ergebnisse liefern. Für eigene Anwendungen ist es also sinnvoll diese Wartezeit per entsprechender Programmfunktion zu berücksichtigen - um ein Falschauslösen zu verhindern.
Die "Blickrichtung" des Sensors ist mit in etwa 110 Grad Weitwinkel nach oben gerichtet.
Nach einer Auslösung des Sensors kann für mindestens drei Sekunden keine weitere Auslösung stattfinden. In dieser Zeit ist der Signalpegel auf "HIGH" gesetzt, d.h. +5V. Siehe auch "Delay" unten in der Grafik.
Die Empfindlichkeit kann in einem Erfassungsbereich von ca. 3 - 7 Meter eingestellt werden.
![[Image: Body_Sensor_01b.png]](https://www.peguino.com/chat/images/Body_Sensor_01b.png)
Beispiel:
Code: /*
Body Sensor Brick
(C) 2018 by Peguino LTD
Connect the Body Sensor Brick to port C2
Connect the RGB LED Brick to port F
Version 1
Note: Use the Serial Plotter to see the values
Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐
3.3 1 │ │ 30 5V
GND 2 │ │ 29 GND
GPIO15 3 │ │ 28 GPIO13
GPIO2 4 │ │ 27 GPIO12
GPIO4 5 │ │ 26 GPIO14
GPIO16 6 │ │ 25 GPIO27
GPIO17 7 │ │ 24 GPIO26
GPIO5 8 │ │ 23 GPIO25
GPIO18 9 │ │ 22 GPIO33
GPIO19 10 │ │ 21 GPIO32
GPIO21 11 │ │ 20 GPIO35
GPIO3 12 │ │ 19 GPIO34
GPIO1 13 │ │ 18 GPIO39
GPIO22 14 │ │ 17 GPIO36
GPIO23 15 │ │ 16 Chip enable
└───┘
Visit https://www.peguino.com
*/
const int buttonPin = 23; // GPIO 23 Pin
// ledPin refers 1:1 to ESP32 GPIO 12, 13 and 14
const int ledPin1 = 13; // red
const int ledPin2 = 12; // green
const int ledPin3 = 14; // blue
int buttonState = LOW; // variable for reading the microphone status
void setup(){
// initialize digital pin ledPin as an output.
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
pinMode(buttonPin, INPUT); // initialize the Button Brick pin as an input
Serial.begin (115200); // Press Ctrl+Shift+M and set the serial monitor to the same baud rate!
Serial.println("Peguino Body Sensor trigger monitor");
}
void loop(){
// read the state of the microphone value:
buttonState = digitalRead(buttonPin);
// now check if the Body Sensor triggers on movement.
if (buttonState != HIGH) {
digitalWrite(ledPin1, LOW); // Red light on
digitalWrite(ledPin2, HIGH); // Green light off
delay (500);
} else {
digitalWrite(ledPin2, LOW); // Green light on because the sensor has triggered on movement!
digitalWrite(ledPin1, HIGH); // Red light off
delay (500);
}
Serial.println(buttonState);
}
|
|
|
Peguino Mikrofon Brick |
Posted by: Peguinohero - 01-09-2019, 07:46 PM - Forum: Alle Peguino Bricks und deren Beschreibungen etc.
- No Replies
|
 |
Peguino Mikrofon Brick
Dieser Peguino Baustein beinhaltet ein Mikrofon mit dem auf Geräusche reagiert werden kann, wie beispielsweise auf ein Händeklatschen.
![[Image: Brick_Microphone_01b.png]](https://www.peguino.com/chat/images/Brick_Microphone_01b.png)
Beispiel:
Code: /*
Microphone Brick
(C) 2018 by Peguino LTD
Connect the Microphone Brick to port D2
Version 1
Note: Use the Serial Monitor to see the values. Press: Ctrl + Shift + M
Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐
3.3 1 │ │ 30 5V
GND 2 │ │ 29 GND
GPIO15 3 │ │ 28 GPIO13
GPIO2 4 │ │ 27 GPIO12
GPIO4 5 │ │ 26 GPIO14
GPIO16 6 │ │ 25 GPIO27
GPIO17 7 │ │ 24 GPIO26
GPIO5 8 │ │ 23 GPIO25
GPIO18 9 │ │ 22 GPIO33
GPIO19 10 │ │ 21 GPIO32
GPIO21 11 │ │ 20 GPIO35
GPIO3 12 │ │ 19 GPIO34
GPIO1 13 │ │ 18 GPIO39
GPIO22 14 │ │ 17 GPIO36
GPIO23 15 │ │ 16 Chip enable
└───┘
Visit https://www.peguino.com
*/
const int buttonPin = 23; // GPIO 23 Pin
// ledPin refers 1:1 to ESP32 GPIO 12, 13 and 14
const int ledPin1 = 13; // red
const int ledPin2 = 12; // green
const int ledPin3 = 14; // blue
int buttonState = LOW; // variable for reading the microphone status
void setup(){
// initialize digital pin ledPin as an output.
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
pinMode(buttonPin, INPUT); // initialize the Button Brick pin as an input
Serial.begin (115200); // Press Ctrl+Shift+M and set the serial monitor to the same baud rate!
Serial.println("Peguino Microphone trigger monitor");
}
void loop(){
// read the state of the microphone value:
buttonState = digitalRead(buttonPin);
// now check if the Microphone triggers on sound. If it is, the buttonState is LOW:
if (buttonState != LOW) {
digitalWrite(ledPin1, LOW); // Red light on
digitalWrite(ledPin2, HIGH); // Green light off
} else {
digitalWrite(ledPin1, HIGH); // Red light off
digitalWrite(ledPin2, LOW); // Green light on
delay (1000); // Let green light shine for one second
}
Serial.println(buttonState);
}
|
|
|
Peguino RC Remote Brick |
Posted by: Peguinohero - 01-09-2019, 07:35 PM - Forum: Alle Peguino Bricks und deren Beschreibungen etc.
- No Replies
|
 |
Peguino RC Remote Brick
Dieser Peguino Baustein beinhaltet einen RC-Funkempfänger der zu den universellen Fly Sky Fernsteuerungen kompatibel ist. Damit kann beispielsweise ein Ferngesteuertes Auto gelenkt werden.
![[Image: Brick_RC_Remote_01b.png]](https://www.peguino.com/chat/images/Brick_RC_Remote_01b.png)
Es können bis zu sechs Standard Peguino Microservo Bricks angeschlossen werden. Mit einem passenden verbindungskabel kann der Baustein aber auch mit einem Peguino Uno Brick verbunden werden und somit Funktionen über eine Fernsteuerung direkt an den Peguino Uno Brick übermittelt werden.
Beispiel:
Code: /*
Sweeperbot (C) 2018 by Peguino LTD
Version 0.5
this example has to be revised and is temporary...
*/
int ledPin1 = 2;
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;
int ledPin5 = 6;
int Ch1, Ch2, Ch3, Ch4, Ch5, Ch6; // Channels
int OnboardLED = LOW; // ledState used to set the LED
int Scheinwerfer = LOW;
int RedLED1 = LOW;
int RedLED2 = LOW;
int BlueLED1 = LOW;
int BlueLED2 = LOW;
unsigned long previousMillis1 = 0; // will store last time LED was updated
unsigned long previousMillis2 = 0;
long interval1 = 20; // interval at which to blink (milliseconds)
long interval2 = 22;
int flicker1 = 0;
int flicker2 = 0;
#define wait 2
#define time 166
int freq = 150;
int auf = 0;
int ab = 0;
void setup() {
// set the digital pin as output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(7, INPUT); //I connected this to Chan5 of the Receiver
pinMode(8, INPUT); //I connected this to Chan6 of the Receiver
// buzzer 9
Serial.begin(9600);
}
void loop() {
int buzzerPin = 9;
// scheiwerfer ein/aus,
// int pwm = 0; // Placeholder for pulsewidth
Ch1 = pulseIn(7, HIGH, 21000); // Capture pulse width on Channel 1
Ch2 = pulseIn(8, HIGH, 21000); // Capture pulse width on Channel 2
// Serial.print("Channel 1 ");
// Serial.println(Ch1);
// Serial.print("Channel 2 ");
// Serial.println(Ch2);
if(Ch1 > 0){
if(Ch1 > 1600){ // Scheinwerfer ein / aus
Scheinwerfer = HIGH;
Serial.print("Scheinwerfer: EIN ");
Serial.println(Ch1);
digitalWrite(ledPin5, Scheinwerfer);
}
else{
Scheinwerfer == LOW;
Serial.print ("Scheinwerfer: AUS ");
Serial.println(Ch1);
digitalWrite(ledPin5, Scheinwerfer);
}
}
if(Ch2 > 0){
if(Ch2 > 1100){ // Scheinwerfer ein / aus
Scheinwerfer = HIGH;
// Serial.print("Scheinwerfer: EIN ");
// Serial.println(Ch1);
digitalWrite(ledPin5, Scheinwerfer);
}
else{
Scheinwerfer == LOW;
// Serial.print ("Scheinwerfer: AUS ");
// Serial.println(Ch1);
digitalWrite(ledPin5, LOW);
}
if(Ch2 > 1500){
// ------ Flashing red and blue LEDs on ----------
unsigned long currentMillis = millis();
// red blink
if (currentMillis - previousMillis1 >= interval1) {
flicker1 += 1;
previousMillis1 = currentMillis;
if (flicker1 == 1) {RedLED1 = HIGH; RedLED2 = LOW;}
if (flicker1 == 2) {RedLED1 = LOW; RedLED2 = HIGH;}
if (flicker1 == 3) {RedLED1 = HIGH; RedLED2 = LOW;}
if (flicker1 == 4) {RedLED1 = LOW; RedLED2 = HIGH;}
if (flicker1 == 5) {RedLED1 = HIGH; RedLED2 = LOW;}
if (flicker1 == 6) {RedLED1 = HIGH; RedLED2 = LOW;}
if (flicker1 == 7) {RedLED1 = HIGH; RedLED2 = LOW;}
if (flicker1 == 8) {RedLED1 = LOW; RedLED2 = HIGH;}
if (flicker1 == 9) {RedLED1 = LOW; RedLED2 = HIGH;}
if (flicker1 >= 10) {RedLED1 = LOW; RedLED2 = HIGH; flicker1 =0;}
digitalWrite(ledPin1, RedLED1);
digitalWrite(ledPin2, RedLED2);
}
// blue blink
if (currentMillis - previousMillis2 >= interval2) {
flicker2 += 1;
previousMillis2 = currentMillis;
if (flicker2 == 1) {BlueLED1 = HIGH; BlueLED2 = LOW;}
if (flicker2 == 2) {BlueLED1 = LOW; BlueLED2 = HIGH;}
if (flicker2 == 3) {BlueLED1 = HIGH; BlueLED2 = HIGH;}
if (flicker2 == 4) {BlueLED1 = LOW; BlueLED2 = HIGH;}
if (flicker2 == 5) {BlueLED1 = HIGH; BlueLED2 = LOW;}
if (flicker2 == 6) {BlueLED1 = LOW; BlueLED2 = HIGH;}
if (flicker2 == 7) {BlueLED1 = HIGH; BlueLED2 = LOW;}
if (flicker2 == 8) {BlueLED1 = LOW; BlueLED2 = HIGH;}
if (flicker2 == 9) {BlueLED1 = LOW; BlueLED2 = LOW;}
if (flicker2 >= 10) {BlueLED1 = LOW; BlueLED2 = HIGH; flicker2 =0;}
digitalWrite(ledPin3, BlueLED1);
digitalWrite(ledPin4, BlueLED2);
// Serial.print ("Blinker: ON ");
// Serial.println(Ch2);
}
}
else {
// ------ Flashing red and blue LEDs off ----------
RedLED1 = LOW;
RedLED2 = LOW;
BlueLED1 = LOW;
BlueLED2 = LOW;
digitalWrite(ledPin1, RedLED1);
digitalWrite(ledPin2, RedLED2);
digitalWrite(ledPin3, BlueLED1);
digitalWrite(ledPin4, BlueLED2);
// Serial.print ("Blinker: OFF ");
// Serial.println(Ch2);
}
}
if(Ch2 > 1800){
if (freq < 1800 && auf == 0)
{
freq += 50;
tone(9, freq, time);
if (freq >= 1800)
{auf = 1; ab = 0;}
}
else
{
freq -= 45;
tone(9, freq, time);
if (freq <= 450)
{auf = 0; ab = 1;}
}
}
if (Ch2 < 1800 && auf == 1 || ab == 1)
{
freq -= 10;
tone(9, freq, time);
if (freq <= 60)
{auf = 0; ab = 0;}
}
//delay(10);
// PrintRC(); //Print Values for RC Mode Diagnostics
}
|
|
|
Peguino Switch Brick (Schalter) |
Posted by: Peguinohero - 01-09-2019, 07:12 PM - Forum: Alle Peguino Bricks und deren Beschreibungen etc.
- No Replies
|
 |
Peguino Switch Brick (Schalter)
Dieser Peguino Baustein beinhaltet einen Ein-/ Ausschalter. Mit ihm kann das Peguino Projekt eingeschalten werden. Der Schalter kann aber auch eine Lampe einschalten etc.
![[Image: Brick_Switch_01b.png]](https://www.peguino.com/chat/images/Brick_Switch_01b.png)
Dieser Baustein kann auch als aktives Element verwendet werden. Dazu kann er mit den Ports C und / oder D verbunden werden. Hierbei ist jedoch zu beachten, dass diese Ports nicht unter Strom gesetzt werden dürfen (dies ist standardmößig der Fall und kann mit den gelben Steckverbindern (Jumper) auf dem Board innerhalb des Peguino Uno Bricks) geöndert werden.) Als Beispiel-Programmscript kann z.B. das Peguino Button Brick-Skript verwendet werden (siehe unten).
Normalerweise wird der Peguino Switch Brick intern auf den schwarten Pin-Konnektor aufgesteckt.
Anmerkung: Sie "Einschaltseite" des Schalters höngt von der Richtung ab, in der der Stecker innen auf das PCB-Board (die Platine im Peguino Uno Brick) aufgesteckt ist. Es sit eine Markierung auf das Board aufgedruckt. Der Schalter wird standardmäßig linksbündig aufgesteckt.
Beispiel:
1. Programmskript für einen Peguino Uno Nano Baustein:
Code: /*
Button Brick
(C) 2018 by Peguino LTD
Connect the Button Brick to port D2
Connect the RGB LED Brick to port F
Version 1
Note: Use the Serial Plotter to see the values
Peguino Uno Nano Board Pinout
┌─╥─┐
D_13 1 │ │ 30 D_12
3.3 V 2 │ │ 29 D_11
AREF 3 │ │ 28 D_10
D_14 A_0 4 │ │ 27 D_9
D_15 A_1 5 │ │ 26 D_8
D_16 A_2 6 │ │ 25 D_7
D_17 A_3 7 │ │ 24 D_6
D_18 A_4 8 │ │ 23 D_5
D_19 A_5 9 │ │ 22 D_4
A_6 10 │ │ 21 D_3
A_7 11 │ │ 20 D_2
5V 12 │ │ 19 GND
Reset 13 │ │ 18 Reset
GND 14 │ │ 17 D_0 RX
Power In 15 │ │ 16 D_1 TX
└───┘
Visit https://www.peguino.com
*/
const int buttonPin = 17; // Digital 17, Analog 3
// ledPin refers 1:1 to ESP32 GPIO 12, 13 and 14
const int ledPin1 = 12; // red
const int ledPin2 = 11; // green
const int ledPin3 = 13; // blue
int buttonState = LOW; // variable for reading the pushbutton status
void setup(){
// initialize digital pin ledPin as an output.
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
pinMode(buttonPin, INPUT); // initialize the Button Brick pin as an input
Serial.begin (115200); // Press Ctrl+Shift+M and set the serial monitor to the same baud rate!
Serial.println("Peguino Button press monitor");
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// now check if the Bbutton brick is pressed. If it is, the buttonState is HIGH:
if (buttonState != LOW) {
digitalWrite(ledPin1, LOW); // Red light on
digitalWrite(ledPin2, HIGH); // Green light off
} else {
digitalWrite(ledPin1, HIGH); // Red light off
digitalWrite(ledPin2, LOW); // Green light on
delay (500); // if you remove the 0.5 seconds waiting time you can see the bouncing spikes interfering the results
}
Serial.println(buttonState);
}
2. Programmskript für einen Peguino Uno ESP32 Baustein:
Code: /*
Button Brick
(C) 2018 by Peguino LTD
Connect the Button Brick to port D2
Connect the RGB LED Brick to port F
Version 1
Note: Use the Serial Plotter to see the values
Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐
3.3 1 │ │ 30 5V
GND 2 │ │ 29 GND
GPIO15 3 │ │ 28 GPIO13
GPIO2 4 │ │ 27 GPIO12
GPIO4 5 │ │ 26 GPIO14
GPIO16 6 │ │ 25 GPIO27
GPIO17 7 │ │ 24 GPIO26
GPIO5 8 │ │ 23 GPIO25
GPIO18 9 │ │ 22 GPIO33
GPIO19 10 │ │ 21 GPIO32
GPIO21 11 │ │ 20 GPIO35
GPIO3 12 │ │ 19 GPIO34
GPIO1 13 │ │ 18 GPIO39
GPIO22 14 │ │ 17 GPIO36
GPIO23 15 │ │ 16 Chip enable
└───┘
Visit https://www.peguino.com
*/
const int buttonPin = 23; // GPIO 23 Pin
// ledPin refers 1:1 to ESP32 GPIO 12, 13 and 14
const int ledPin1 = 13; // red
const int ledPin2 = 12; // green
const int ledPin3 = 14; // blue
int buttonState = LOW; // variable for reading the pushbutton status
void setup(){
// initialize digital pin ledPin as an output.
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
pinMode(buttonPin, INPUT); // initialize the Button Brick pin as an input
Serial.begin (115200); // Press Ctrl+Shift+M and set the serial monitor to the same baud rate!
Serial.println("Peguino Button press monitor");
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// now check if the Bbutton brick is pressed. If it is, the buttonState is HIGH:
if (buttonState != HIGH) {
digitalWrite(ledPin1, LOW); // Red light on
digitalWrite(ledPin2, HIGH); // Green light off
} else {
digitalWrite(ledPin1, HIGH); // Red light off
digitalWrite(ledPin2, LOW); // Green light on
delay (500); // if you remove the 0.5 seconds waiting time you can see the bouncing spikes interfering the results
}
Serial.println(buttonState);
}
|
|
|
|