Page 1 of 1

make few sound with a motor dc

Posted: Fri Nov 02, 2018 9:06 am
by froussel
By ordering the output pwm and / or the high of the H-bridge which commands the motor dc I saw a long time ago how to produce some sounds.
But I forget that.

I want to identify with the start of the micro controller that everything is ok after the motor will be normaly commanded

A piece of code with IDE arduino would be appreciated or an URL

Re: make few sound with a motor dc

Posted: Fri Nov 02, 2018 2:23 pm
by rudi ;-)
froussel wrote:
A piece of code ...

did not played with this on esp32..
and not from me, but think should be can transformed to the esp32 that work's
hope this helps you:

Code: Select all

void playSound(uint16_t freq, uint16_t duration_msec, uint8_t  amplitude) {
  uint32_t n,k,period_usec,duration_usec;
  period_usec = 1000000L / freq;
  duration_usec = 1000 * (uint32_t) duration_msec;
  k = duration_usec / period_usec;
  motorSpeed (amplitude, amplitude);
  for (n = 0; n < k; n++)   {
    motorDirection (DIR_FORWARD, DIR_FORWARD);
    delayMicroseconds(period_usec/2);
    motorDirection (DIR_REVERSE, DIR_REVERSE);
    delayMicroseconds(period_usec/2);
  }
  motorSpeed (0, 0);
}
for inspiration

best wishes
rudi ;-)

...or an ULR ...
sure .. here you go
and .. here

Re: make few sound with a motor dc (solved)

Posted: Tue Nov 13, 2018 12:33 pm
by froussel
Thanks!
Just must do it now :-)

Re: make few sound with a motor dc

Posted: Wed Dec 12, 2018 10:03 pm
by froussel
I tried
  1. void motorAv()
  2.   {     digitalWrite(inaPin, HIGH);                              
  3.         digitalWrite(inbPin, LOW);      }
  4.  
  5. void motorAr()
  6.   {        digitalWrite(inaPin, LOW);                              
  7.            digitalWrite(inbPin, HIGH);         }  
  8.  
  9. void motorStop()              
  10.        {   digitalWrite(inaPin, LOW);                              
  11.            digitalWrite(inbPin, LOW);      }      
  12.  
  13.  
  14. void playSound(uint16_t freq, uint16_t duration_msec, uint8_t amplitude)
  15. {  uint32_t n,k,period_usec,duration_usec;
  16.    period_usec = 1000000L / freq;
  17.    duration_usec = 1000 * (uint32_t) duration_msec;
  18.    k = duration_usec / period_usec;
  19.    pwm= amplitude;                              // pwm max driver motor = 100%
  20.    for (n = 0; n < k; n++)
  21.      {  motorAv();
  22.         delayMicroseconds(period_usec/2);
  23.         motorAr();
  24.         delayMicroseconds(period_usec/2); }
  25.    motorStop;                                    }
  26.        
  27.  
  28.  uint16_t freq = 1000;     // max 65535
  29.   uint16_t duration_msec = 400;
  30.   uint8_t amplitude=255;
  31.   for (int i =15000; i < 19000; i = i +100)
  32.     {  delay(100);
  33.        playSound(i, duration_msec, amplitude);
  34.     }
No sound

please why ?

Re: make few sound with a motor dc

Posted: Wed Dec 19, 2018 7:50 pm
by froussel
I'm alone ?

Re: make few sound with a motor dc

Posted: Fri Dec 21, 2018 8:12 am
by rudi ;-)
did you test, you can drive the motor normal?
is the motor working? how much sink it?
which motor you use?

how you drive the motor by hardware?
or do you use (later) motor drivers ics? ( example uln2003 )
and how looks your hardware setup?

best wishes
rudi ;-)

Re: make few sound with a motor dc

Posted: Fri Dec 21, 2018 11:44 am
by froussel
rudi ;-) wrote:
Fri Dec 21, 2018 8:12 am
did you test, you can drive the motor normal?
Yes
is the motor working? how much sink it?
which motor you use?
Brushed DC motor
how you drive the motor by hardware?
or do you use (later) motor drivers ics? ( example uln2003 )
and how looks your hardware setup?
Thing as https://www.pololu.com/product/708

When reading this
http://esp8266.github.io/Arduino/versio ... log-output
I wonder if I have an error in the maximum of 255 for the pwm
Should not I put 1023 instead?
best wishes
rudi ;-)
Also ;-)

Re: make few sound with a motor dc

Posted: Tue Oct 15, 2019 8:27 am
by tancojoony
did you test, you can drive the motor normal?
is the motor working? how much sink it?
which motor you use?




-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
My stepper motor website:skysmotor.com - Machinery Design • - • Stepper Moter Development
"Necessity is the mother of invention." - Author unknown.
as you type.