Bootloader

Bonjour,

J'ai fait le test sur plusieurs arduino uno, le code suivant permet bien de lancer un serveur web uniquement si je branche le port USB sur mon pc.

Explication :
Si je branche l'arduino uno + shield ethernet sur l'alim 9V + cordon ethernet,
alors toutes les leds de la carte ethernet ne clignote pas et l'accès au serveur web ne marche pas.
Si je branche comme ci-dessus + le port USB,
alors les leds de la carte ethernet clignote et l'accès au serveur web fonctionnement normalement.

Est ce que ca provient du code ou du bootloader ?
je me demandais si j'avais pas un problème matériel mais sur plusieurs cartes ce serait surprenant.

#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <Servo.h>

#define DHTPIN 2     // what digital pin we're connected to
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);

boolean HTTPreading = false;
// Setup the static network info for you arduino
//byte ip[] = { 192, 168, 1, 30 };   // IP Address bureau
byte ip[] = { 192, 168, 1, 31 };   // IP Address extérieur
byte subnet[] = { 255, 255, 255, 0 }; // Subnet Mask
byte gateway[] = { 192, 168, 1, 1 }; // Gateway
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xAB }; // MAC Address

EthernetServer server = EthernetServer(80); // Port 80
String HTTPget = "";

IPAddress server_addr(192,168,1,5);  // IP of the MySQL *server* here
char user[] = "admin";              // MySQL user login username
char password[] = "16y18o13a14";        // MySQL user login password
EthernetClient client;
MySQL_Connection conn((Client *)&client);
char INSERT_SQL[200] = "";

unsigned long lastSend=0;

Servo myservo;

void setup()
{
  // pin 10, 11, 12 and 13 are used by the ethernet shield
  Ethernet.begin(mac, ip, gateway, subnet); // setup ethernet with params from above
  server.begin();
  dht.begin();
  pinMode(5, OUTPUT);
  myservo.attach(9);
  Serial.begin(9600);
  Serial.println("setup finish!");
}

void loop()
{
  float DHThumidity = dht.readHumidity();
  float DHTtemperature = dht.readTemperature();
  //Serial.print("temperature = ");  Serial.println(temperature);

  if(lastSend>millis()) lastSend=0;

  if (millis()-lastSend>3600000) {
    Serial.println("Connecting...");
    if (conn.connect(server_addr, 3306, user, password)) {
      delay(1000);
      memset(INSERT_SQL, 0, 200);
      lastSend=millis();
      char temp_buff[5];
      MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);    // Initiate the query class instance
      strcat(INSERT_SQL, "INSERT INTO home.sensor (nom,type,valeur) VALUES ('exterieur','temperature','");
      dtostrf(DHTtemperature,5, 1, temp_buff);
      strcat(INSERT_SQL, temp_buff);
      strcat(INSERT_SQL, "')");
      Serial.println("Envoi mysql :");
      Serial.println(INSERT_SQL);
      cur_mem->execute(INSERT_SQL);    // Execute the query, Note: since there are no results, we do not need to read any data

      conn.close();                  // close the connection
      delete cur_mem;        // Deleting the cursor also frees up memory used
    }
    else
      Serial.println("Connection failed.");

  }
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) 
  {
    HTTPget=processClient(client);

    int k= HTTPget.indexOf('/');
    int L=0;
    int value=0;
    String order="";
    if (k!=-1) {
      L=HTTPget.length();
      String temp=HTTPget.substring(k+1,L);  
      value= temp.toInt();
      order=HTTPget.substring(0,k);
    }
    
    if (HTTPget=="status") {
      char outstr[4];
      client.println("<status>");
      client.print("    <humidity>");
            dtostrf(DHThumidity,4, 1, outstr);
      client.print(outstr);
      client.println("</humidity>");
      client.print("    <temperature>");
            dtostrf(DHTtemperature,4, 1, outstr);
      client.print(outstr);
      client.println("</temperature>");
      client.println("</status>");
    }
    else if (HTTPget=="D5on") {
      digitalWrite(5, HIGH);   // turn the LED on (HIGH is the voltage level)
      client.println("D5 : on.");
    }
    else if (HTTPget=="D5off") {           
      digitalWrite(5, LOW);    // turn the LED off by making the voltage LOW
      client.println("LD5 : off.");
    }
    else if (order=="SERVO") {           
      myservo.write(value);    
      client.print("servo : ");
      client.println(order);
      client.print("value : ");
      client.println(value);
    }
    else
      client.println("Hello ! No parameter received...");

    client.println(HTTPget.substring(0,5));
    
    delay(1); // give the web browser a moment to recieve
    client.stop(); // close connection
    HTTPget = ""; // clear out the get param we saved
  
  }
}

String processClient(EthernetClient client)
{
  // http request will end with a blank line
  boolean lineIsBlank = true;

  while (client.connected())
  {
    if (client.available())
    {
      char c = client.read();

      if(HTTPreading && c == ' ') HTTPreading = false;
      if(c == '?') HTTPreading = true; // ? in GET request was found, start reading the info

      //check that we are reading, and ignore the '?' in the URL, then append the get parameter into a single string
      if(HTTPreading && c != '?') HTTPget += c;

      if (c == '\n' && lineIsBlank)  break;

      if (c == '\n') {
        lineIsBlank = true;
      }
      else if (c != '\r') {
        lineIsBlank = false;
      }

    }
  }
  //client.println(HTTPget);
  return HTTPget;
}

Merci d'avance pour votre aide.
Julien

Un shield Ethernet + un servo. L'alimentation ne serait pas un peu anémique par hasard?

  • 1

Note que le bootloader ne sert qu'au transfert du programme dans le micro.
Atmel vend ses micro sans bootloader car si le bootloader simplifie l'opération de programmation il n'est pas indispensable. Il existe une autre solution de programation qui n'exige pas bootloader.

Alors les tests ont été fait sans servo branché.

J'ai refait des tests entre plusieurs carte et ça semble être un problème de compatibilité entre certaine carte uno et carte ethernet chinoise.

68tjs:

  • 1

Note que le bootloader ne sert qu'au transfert du programme dans le micro.
Atmel vend ses micro sans bootloader car si le bootloader simplifie l'opération de programmation il n'est pas indispensable. Il existe une autre solution de programation qui n'exige pas bootloader.

hello !!!

Pourrais tu me donner plus d'info et liens pour la programmation sans bootloader ???

Je recherche à faire cela sans usb .. Over IP serait le top pour moi !!!

Merci beaucoup par avance

Pour les détails le site arduino et gogole sont tes amis.

Il faut utiliser le mode ISP et le connecteur 6 broches à l'arrière de la carte UNO.
Attention le mode ISP utilise des pinuches utilisées par le SPI mais ce n'est pas la même chose (1).
Si par ailleurs tu utilises les pins SPI dans ton montage je ne sais pas s'il peut y avoir conflit.

Pour programmer tu peux utiliser soit une carte UNO en y téléchargeant le programme qui va bien. C'est parfaitement expliqué sur le site arduino, soit acheter pour quelques euros un programmeur prévu pour (USBasp ou tynyUSB).

Dans l'IDE il faut aussi sélectionner le bon programmeur : c'est expliqué sur ce site.

(1) le nombre de pins de sortie étant limité il est courant que la même pin physique ait plusieurs fonctions. Dans le cas présent c'est une action du programmeur qui positionne en mode ISP.