Hi there,
I'm a total newbie in the field of microcontrollers and MicroPython.
I have a small project in mind in which I would like to make a laser module pulse very very slowly. Bringing up and down the voltage from 0V to 5V and back.
The laser module is already connected to the controller. I can turn it on/off and blink, but I would like to have more control over the voltage and time.
Is there somebody who can point me in a direction where to look or even has a solution for me to use?
Thank you,
Wouter
Microcontroller adjusting voltage of laser module
-
- Posts: 4
- Joined: Sat Dec 04, 2021 3:20 pm
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Microcontroller adjusting voltage of laser module
You need a DAC (digital to analog converter). Some MicroPython targets have these built-in (e.g. Pyboards). Otherwise they can be bought or built using a resistor network and an op amp - but this needs some skill in electronic construction.
But the firs step is to determine if your laser module is characterised to work at low voltages. It's possible that it won't "lase" until the voltage reaches a threshold. If you want to vary its brightness you may need to pulse it at high frequency, varying the duty ratio. But cheap laser modules don't like this either...
But the firs step is to determine if your laser module is characterised to work at low voltages. It's possible that it won't "lase" until the voltage reaches a threshold. If you want to vary its brightness you may need to pulse it at high frequency, varying the duty ratio. But cheap laser modules don't like this either...
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 4
- Joined: Sat Dec 04, 2021 3:20 pm
Re: Microcontroller adjusting voltage of laser module
Thank you for your reply.
Unfortunately, the Raspberry Pico doesn't have a built-in DAC.
Although it has a built-in PWM. Would it be possible to create a sin-wave with the PWM?
Unfortunately, the Raspberry Pico doesn't have a built-in DAC.
Although it has a built-in PWM. Would it be possible to create a sin-wave with the PWM?
-
- Posts: 4
- Joined: Sat Dec 04, 2021 3:20 pm
Re: Microcontroller adjusting voltage of laser module
I have found this code that works by fading the laser in and out.
But I can't seem to find where to adjust the code and make the fade in and out slower.
But I can't seem to find where to adjust the code and make the fade in and out slower.
Code: Select all
led = Pin(20)
pwm = PWM(led)
pwm.freq(1000)
duty = 0
direction = 1
for repeat in range (2000):
duty += direction
if duty > 200:
duty = 200
direction = -1
elif duty < 0:
duty = 0
direction = 1
pwm.duty_u16(duty * duty)
utime.sleep(0.01)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Microcontroller adjusting voltage of laser module
Try adjusting the sleep time - utime.sleep(0.01)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 4
- Joined: Sat Dec 04, 2021 3:20 pm
Re: Microcontroller adjusting voltage of laser module
Amazing, what fun to play around with microcontrollers and micropython.
Thank you for the support!
Thank you for the support!