Voici un programme afin d’interfacer le capteur VL6180X avec la carte Esus. Le capteur est relié par bus I2C à la carte Esus. Le capteur VL6180X est capteur de distance “Time of Flight” de mesure laser de distance de 0 à 200 mm.
#include <ESP8266WiFi.h>#include <WiFiUDP.h>#include <mrduino.h>static void read_receptionCommande(String Commande);int status = WL_IDLE_STATUS;const char* ssid = "YOUR_SSID"; // your network SSID (name)const char* pass = "YOUR_PASS"; // your network passwordunsigned int localPort = 12345; WiFiUDP Udp;int tries=0;void setup(){ // Open serial communications and wait for port to open: Serial.begin(115200); // setting up Station AP WiFi.begin(ssid, pass); // Wait for connect to AP Serial.print("[Connecting]"); Serial.print(ssid); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); tries++; if (tries > 30) { break; } } Serial.println(); printWifiStatus(); Serial.println("Connected to wifi"); Serial.print("Udp server started at port "); Serial.println(localPort); Udp.begin(localPort);}void loop(){int noBytes = Udp.parsePacket();String received_command = "";byte packetBuffer[512]; if ( noBytes ) { Serial.print("received a packet"); // We've received a packet, read the data from it Udp.read(packetBuffer,noBytes); // read the packet into the buffer for (int i=1;i<=noBytes;i++) { received_command = received_command + char(packetBuffer[i - 1]); } // end for Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); Udp.endPacket(); // execution de la commande Serial.println(received_command); } // end if}void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);}
Compiler et télécharger le programme dans le robot MRduino Wireless
Le programme de contrôle
Lien pour télécharger le programme de contrôle (dossier Zip): MrduinoControler
Remarque : programme pour Windows
Dézipper le dossier :
Lancer le programme MRduinoControler.exe
Ce programme permet de contrôler les mouvements du robot et les trois leds. Ne pas oublier de saisir l’adresse IP correct du robot.
Une vidéo de l’association AMIC de Chambray lès Tours dans une classe de CM2 avec la programmation des robots MRduino Wireless. Le robot MRduino est programmable en langage graphique adapté aux enfants.
Un tutoriel pour le contrôle du haut-parleur sur le robot MRduino Wireless en langage Arduino.
Le matériel nécessaire:
Un câble femelle-femelle d’une longueur de 20 cm.
Le câblage
Le câble femelle-femelle doit être connecté entre la pin IO2 de la carte Esus et le connecteur du haut parleur nommé ‘S’. Le connecteur du haut parleur est un connecteur 2 pins près du connecteur de la batterie.
/* Melody Plays a melody circuit: * 2-ohm speaker on digital pin 8 created 21 Jan 2010 modified 30 Aug 2011 by Tom Igoe modified 15/05/2017 by Mace Robotics for MRduino Wireless robotThis example code is in the public domain. http://www.arduino.cc/en/Tutorial/Tone */#include <mrduino.h>#include <esusBoard.h>#include "pitches.h"int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4};int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4};void setup(){ Serial.begin(115200); speakerEnable(); pinMode(2, OUTPUT); for (int thisNote = 0; thisNote < 8; thisNote++) {// to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000 / noteDurations[thisNote]; tone(2, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes);// stop the tone playing: noTone(2); }}void loop() {}
Après avoir vérifié ce programme Arduino, vous pouvez le téléverser vers le robot via un câble micro-USB.
Transfére en Wifi
Maintenant que vous avez programmer le robot, vous pouvez fermer le logiciel Arduino IDE et le redémarrez afin d’avoir une nouvelle option de programmation.
Ouvrez l’onglet Tools->Port :
Sélectionner le port : monMRduinoW
Vous pouvez débrancher le câble série de type micro-USB entre votre robot et le PC; et téléverser à nouveau le programme. Cette fois-ci, le téléversement fonctionne en Wifi.