Go Down

Topic: The sketch run ok but if I disconnect then i have to upload the program again. (Read 3264 times) previous topic - next topic

lisandro24

The sketch run ok but if I disconnect and reconnect then i have to upload the program again.  I tried to disable serial or try with delay but i cant fix the problem.

thaks!!

johnwasser

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


cmiyc

Where did you purchase it from?  If you do not have the capability to reflash the bootlaoder yourself, you may want to return it.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

AlxDroidDev

Can you post your sketch?

Are you by chance using pins 0, 1 on your sketch? If so, are your properly setting up their directions (INPUT, OUTPUT) and initial state (HIGH, LOW) in the setup() function?
Some of my projects:
Shield for DS1337+, DS1624 and AT24C1024B (RTC, temp & mem): http://forum.arduino.cc/index.php/topic,126197.0.html
CHDK Camera remote shutter (BT, IR, USB): http://forum.arduino.cc/index.php?topic=295377.0

lisandro24

This is the code thank you again!!

Run ok if i previus upload the sketch or if i reset but if unplug/plug USB power, it fail.


Code: [Select]


include <MIDI.h>

int piezo = 0;    // select the input pin for the piezo
int piezo1 = 1;
int piezo2 = 2;
int piezo3 = 3;
int piezo4 = 4;
int piezo5 = 5;


int sensorValue = 0;
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;
int sensorValue5 = 0;


void setup() {

  Serial.begin (31250);
 
  pinMode (0, INPUT);
  pinMode (1, INPUT);
  pinMode (2, INPUT);
  pinMode (3, INPUT);
  pinMode (4, INPUT);
  pinMode (5, INPUT);

}

void loop() {
 
MIDI.begin(1); 
 
   sensorValue = analogRead(piezo)/200;// read the value from the sensor,
  sensorValue1 = analogRead(piezo1)/310;
  sensorValue2 = analogRead(piezo2)/100;
  sensorValue3 = analogRead(piezo3)/500;
  sensorValue4 = analogRead(piezo4)/100;
  sensorValue5 = analogRead(piezo5)/165; 

  if (sensorValue > 1) {
   
    MIDI.sendNoteOn(36,127,sensorValue/3);  // kick
    delay(1); //
    MIDI.sendNoteOff(36,0,0);   //
  } 
  if (sensorValue1 > 1) {
   
    MIDI.sendNoteOn(38,127,sensorValue1/3);  // SNARE
    delay(1); // Wait for a second
    MIDI.sendNoteOff(38,0,0);   // Stop the note
  }
  if (sensorValue2 > 1) {
   
    MIDI.sendNoteOn(48,127,sensorValue2/3);  // HI HATS
     delay(1);
    MIDI.sendNoteOff(48,0,0);
  }   
  if (sensorValue3 > 1) {
   
    MIDI.sendNoteOn(71,127,sensorValue3);  //  TOM 1
    delay(1);
    MIDI.sendNoteOff(71,0,0);   

  }

  if (sensorValue4 > 1) {
   
    MIDI.sendNoteOn(45,127,sensorValue4/2);  // RIDE
    delay(1);
    MIDI.sendNoteOff(45,0,0);   
  }
  if (sensorValue5 > 1) {
   
    MIDI.sendNoteOn(57,127,sensorValue5/2);  // hi hat OPEN
    delay(1);
    MIDI.sendNoteOff(57,0,0); 
  }
}

cmiyc

Quote
Code: [Select]
[ pinMode (0, INPUT);
  pinMode (1, INPUT);
  pinMode (2, INPUT);
  pinMode (3, INPUT);
  pinMode (4, INPUT);
  pinMode (5, INPUT);

Yeah, that's going to be a problem.  You are setting the digital pins, not the analog pins.

1.  Analog pins should be referred to with A0, A1, etc. 
2.  You don't need to call pinMode(INPUT) on analog pins.  It is ONLY for digital operations.  analogRead() handles it.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

lisandro24

Sorry this is the original code, without the wrong initialization but still has the same problem.

thanks!!

Code: [Select]

#include <MIDI.h>


int piezo = A0;    // select the input pin for the piezo
int piezo1 = A1;
int piezo2 = A2;
int piezo3 = A3;
int piezo4 = A4;
int piezo5 = A5;


int sensorValue = 0;
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;
int sensorValue5 = 0;


void setup() {

  Serial.begin (31250);


MIDI.begin(1); 
   
}

void loop() {
 

 
   sensorValue = analogRead(piezo)/200;// read the value from the sensor,
  sensorValue1 = analogRead(piezo1)/310;
  sensorValue2 = analogRead(piezo2)/100;
  sensorValue3 = analogRead(piezo3)/500;
  sensorValue4 = analogRead(piezo4)/100;
  sensorValue5 = analogRead(piezo5)/165; 

  if (sensorValue > 1) {
   
    MIDI.sendNoteOn(36,127,sensorValue/3);  // kick
    delay(1); //
    MIDI.sendNoteOff(36,0,0);   //
  } 
  if (sensorValue1 > 1) {
   
    MIDI.sendNoteOn(38,127,sensorValue1/3);  // SNARE
    delay(1); // Wait for a second
    MIDI.sendNoteOff(38,0,0);   // Stop the note
  }
  if (sensorValue2 > 1) {
   
    MIDI.sendNoteOn(48,127,sensorValue2/3);  // HI HATS
     delay(1);
    MIDI.sendNoteOff(48,0,0);
  }   
  if (sensorValue3 > 1) {
   
    MIDI.sendNoteOn(71,127,sensorValue3);  //  TOM 1
    delay(1);
    MIDI.sendNoteOff(71,0,0);   

  }

  if (sensorValue4 > 1) {
   
    MIDI.sendNoteOn(45,127,sensorValue4/2);  // RIDE
    delay(1);
    MIDI.sendNoteOff(45,0,0);   
  }
  if (sensorValue5 > 1) {
   
    MIDI.sendNoteOn(57,127,sensorValue5/2);  // hi hat OPEN
    delay(1);
    MIDI.sendNoteOff(57,0,0); 
  }
}


cmiyc

The serial stuff is likely a red herring.

If the Uno is forgetting the code when you power cycle, you may have an older bootloader programmed.  (There was an issue early-on.)

The next step is to re-flash the bootloader yourself or to contact the seller and return it.  If it is a genuine Arduino (which is suspect to why someone would have inventory from 2 years ago), they should exchange it for you.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

dannable

On the back it will say 'Board Model'. Is it an Uno R2 by any chance?
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

lisandro24

But if i run the examples, like blinking there is no problem. I dissconect and then connect and the sketch is OK.

johnwasser


But if i run the examples, like blinking there is no problem. I dissconect and then connect and the sketch is OK.


That usually means there is something wrong with YOUR sketch. Perhaps there is something wrong in the MIDI libary.  Where did you get it?
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


johnwasser


The library is in the arduino 1.0.4.


It's not with my copy of Arduino 1.0.5.  Are you SURE you didn't get it from a third-party?  Perhaps the MIDI.h file will have comments saying where it came from.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up