Home Forums Sparkfun MP3 Shield Library Support Forum Library and Ultrasonic Sensors Reply To: Library and Ultrasonic Sensors

#1853
Bill
Member

Nader,

Give us more details on the types of sensors you are using and what code runs them. Are you sure they are analog sensors and not PWM output? I can see a problem trying to use PWM input sensors with the MP3 library as there would be simultaneous interrupt conflicts. However pure analog sensors should not interfere with the MP3 functions.

Try wrapping your sensor code in the MP3 data stream functions, like this:

 

 //disable interrupts to avoid collisions on the SPI bus between this code //and the MP3player library
  MP3player.pauseDataStream();

  //Sensor code here, for example if it's a PWM sensor
  digitalWrite(TRIG_PIN, HIGH); // Send a 10uS high to trigger ranging
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  // Now ping for objects
  int distance = pulseIn(ECHO_PIN, HIGH);        // Read in times pulse

  //enable interrupts to resume sending data to MP3 shield
  MP3player.resumeDataStream();

That’s what it would look like if you had a PWM based sensor.