Example sketch

Issue #2 resolved
Former user created an issue

Hi-

I'm running into the below error when I try to compile the EventTimer example sketch. I'm trying to compile it for the Arduino Gemma (https://www.adafruit.com/product/2470) board. The vanilla example builds fine, and the EventTimer sketch builds fine using an Uno board. I assume this prob has to do with the Gemma using a diff chip

NewPingEventTimer.pde: In function 'void loop()': NewPingEventTimer:32: error: 'class NewPing' has no member named 'ping_timer' NewPingEventTimer.pde: In function 'void echoCheck()': NewPingEventTimer:39: error: 'class NewPing' has no member named 'check_timer' 'class NewPing' has no member named 'ping_timer'

Comments (3)

  1. Tim Eckel repo owner

    You can't use the timer methods with the ATtiny microcontroller. My library detects that you're running an ATtiny and disables the timer methods, which is why it's reporting that it can't find the methods: ping_timer and check_timer.

    Basically, the microcontroller on the Gemma doesn't support what you're trying to do. NewPing will only work with the non-timer methods on the ATtiny (microcontroller limitation, not NewPing). The library is working correctly by disabling those methods. If it didn't disable those methods, you couldn't compile the non-timer methods (like using ping() or ping_median() which is fully supported).

    See the NewPingExample sketch, that will compile (once you remove the Serial stuff as the ATtiny84 doesn't support that either). Or, this sketch as a starter (which you'll need to expand to do what you want with the cm variable.

    #include <NewPing.h>
    
    NewPing sonar(0, 2, 200); // NewPing setup of trigger pin, echo pin, and maximum distance.
    
    void setup() {}
    
    void loop() {
      delay(50);
      uint8_t cm = sonar.ping_cm(); // Variable cm provides the distance measurement or zero if out of range.
    }
    
  2. Tim Eckel repo owner

    Library is working correctly. Disables timer methods because the ATtiny doesn't support them. This is a hardware limitation of the ATtiny, not NewPing.

  3. Log in to comment