#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.
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.