Firmata with Ultrasonic sensor from Arduino to oF


I would like to connect my ultrasonic sensor from Arduino to openFrameworks with Firmata. I was pulling the code from the Ping and Firmata examples. However, it reads some very weird digits like “üñýüüüüü” rather than the distance in inches.

Below is my code and can someone tell me what have I done wrong please?

#include <Firmata.h>  
const int pingPin = 7;  

void setup()  

void loop()  
   while(Firmata.available()) {  

   Firmata.sendAnalog(pingPin, computeDistance());  

long computeDistance(){  
 long duration, inches, cm;  
  pinMode(pingPin, OUTPUT);  
  digitalWrite(pingPin, LOW);  
  digitalWrite(pingPin, HIGH);  
  digitalWrite(pingPin, LOW);  

  pinMode(pingPin, INPUT);  
  duration = pulseIn(pingPin, HIGH);  

  // convert the time into a distance  
  return microsecondsToInches(duration);  


long microsecondsToInches(long microseconds)  
  return microseconds / 74 / 2;  

// long microsecondsToCentimeters(long microseconds) 
// {  
//   return microseconds / 29 / 2;  
// }
Below is my code and can someone tell me what have I done wrong please?

Yes. When you installed Firmata, you gave up having the ability to control any pins on the Arduino itself. So, you can NOT diddle with the pins you need to in order to make the ping sensor work.

You can NOT push distance data anywhere, even if you were able to get any.