Go Down

Topic: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7 (Read 667427 times) previous topic - next topic

MuhammadMohtashim

Hello, I am looking for a way to use 4 sensors with this code. Which it superbly does. It's an amazing piece of code. But I am looking to average the readings from the 4 sensors. My problem is the last bit of code

for (uint8_t i = 0; i < SONAR_NUM; i++) {
    Serial.print(i);
    Serial.print("=");
    Serial.print(cm);
    Serial.print("cm ");
  }

Just pushes the readings in four separate ways. How can I take the readings from the 4 sensors and get their average and put out on the screen?

Thank you.

TheMemberFormerlyKnownAsAWOL

Add them all together and divide by four.

Please remember to use code tags when posting code
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

thatimetat

What sense does it make for return type of ping_median() to be unsigned long when the array uS[it] is of type unsigned int?

juanjnd


MuhammadMohtashim

Add them all together and divide by four.

Please remember to use code tags when posting code
Yes..But how?

worked with 2 sensors. Tried adding cm[0] and cm[1] together but the values I get are bigger. For example if the sensor 1 is 9cm so cm[0] should also be 9cm but it is 90cm.

I created a new array "fyp' and used memcpy to copy the cm array into it but only the cm[0] gets copied to  fpy[0] and fyp[1] is 0cm even when cm[1] gives 10cm

TheMemberFormerlyKnownAsAWOL

Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

robodrone

Any idea how to get this working on the new Arduino Nano Every? 

Trying to compile some code and getting loads of errors around. Some of the names I see are "TIMSK2", "OCR2A", "TCNT2" and "TCCR2B". 

The code itself is fine but this library doesn't seem to work. I have the latest version (1.9.1). 

ballscrewbob

@robodrone

That is because of the MCU differing architectures.
You need to find a library that is SPECIFIC to the EVERY.

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google (who would have thunk it ! ) or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

robodrone

That is because of the MCU differing architectures.
You need to find a library that is SPECIFIC to the EVERY.
Yeah I know that, it's been causing some issues with libraries, some I can do without but some I kinda need.
AFAIK the NewPing library is the only one that supports running the HC-SR04 sensor using just one wire. I might have enough pins to do it the old fashioned way if that's the only choice.
HC-SR04

teckel

Yeah I know that, it's been causing some issues with libraries, some I can do without but some I kinda need.
AFAIK the NewPing library is the only one that supports running the HC-SR04 sensor using just one wire. I might have enough pins to do it the old fashioned way if that's the only choice.
HC-SR04
There's basically two libraries in one with NewPing.  One is designed for legacy ATmega devices that uses direct port manipulation and timers for speed and low memory usage.  The other uses conventional commands that works with other hardware.


How the library decides if it should use ATmega code or general code, is the section starting in line 189 in NewPing.h:


    // Detect non-AVR microcontrollers (Teensy 3.x, Arduino DUE, etc.) and don't use port registers or timer interrupts as required.
    #if (defined (__arm__) && (defined (TEENSYDUINO) || defined (PARTICLE)))


All you need to do is let me know what is defined to identify the EVERY.  Maybe it's "EVERY"?  Maybe "__EVERY__" I have no idea.  Then, submitted to me to be added to a pull request.


Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

bertenvdb

// Detect non-AVR microcontrollers (Teensy 3.x, Arduino DUE, etc.) and don't use port registers or timer interrupts as required.
    #if (defined (__arm__) && (defined (TEENSYDUINO) || defined (PARTICLE)))

All you need to do is let me know what is defined to identify the EVERY.  Maybe it's "EVERY"?  Maybe "__EVERY__" I have no idea.  Then, submitted to me to be added to a pull request.
The Nano Every is identified as "AVR_NANO_EVERY" (source code)

Would be awesome if NewPing would support the Nano Every. 

Go Up