make few sound with a motor dc

froussel
Posts: 21
Joined: Fri Jul 13, 2018 7:13 am

make few sound with a motor dc

Postby froussel » Fri Nov 02, 2018 9:06 am

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

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: make few sound with a motor dc

Postby rudi ;-) » Fri Nov 02, 2018 2:23 pm

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
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

froussel
Posts: 21
Joined: Fri Jul 13, 2018 7:13 am

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

Postby froussel » Tue Nov 13, 2018 12:33 pm

Thanks!
Just must do it now :-)

froussel
Posts: 21
Joined: Fri Jul 13, 2018 7:13 am

Re: make few sound with a motor dc

Postby froussel » Wed Dec 12, 2018 10:03 pm

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 ?

froussel
Posts: 21
Joined: Fri Jul 13, 2018 7:13 am

Re: make few sound with a motor dc

Postby froussel » Wed Dec 19, 2018 7:50 pm

I'm alone ?

User avatar
rudi ;-)
Posts: 1698
Joined: Fri Nov 13, 2015 3:25 pm

Re: make few sound with a motor dc

Postby rudi ;-) » Fri Dec 21, 2018 8:12 am

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 ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

froussel
Posts: 21
Joined: Fri Jul 13, 2018 7:13 am

Re: make few sound with a motor dc

Postby froussel » Fri Dec 21, 2018 11:44 am

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 ;-)

tancojoony
Posts: 1
Joined: Tue Oct 15, 2019 7:18 am

Re: make few sound with a motor dc

Postby tancojoony » Tue Oct 15, 2019 8:27 am

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.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 97 guests