Microcontroller adjusting voltage of laser module

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
wouterjesse
Posts: 4
Joined: Sat Dec 04, 2021 3:20 pm

Microcontroller adjusting voltage of laser module

Post by wouterjesse » Sat Dec 04, 2021 3:45 pm

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Microcontroller adjusting voltage of laser module

Post by pythoncoder » Sun Dec 05, 2021 11:05 am

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...
Peter Hinch
Index to my micropython libraries.

wouterjesse
Posts: 4
Joined: Sat Dec 04, 2021 3:20 pm

Re: Microcontroller adjusting voltage of laser module

Post by wouterjesse » Sun Dec 05, 2021 3:38 pm

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?

wouterjesse
Posts: 4
Joined: Sat Dec 04, 2021 3:20 pm

Re: Microcontroller adjusting voltage of laser module

Post by wouterjesse » Sun Dec 05, 2021 4:32 pm

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.

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)  

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Microcontroller adjusting voltage of laser module

Post by pythoncoder » Sun Dec 05, 2021 6:51 pm

Try adjusting the sleep time - utime.sleep(0.01)
Peter Hinch
Index to my micropython libraries.

wouterjesse
Posts: 4
Joined: Sat Dec 04, 2021 3:20 pm

Re: Microcontroller adjusting voltage of laser module

Post by wouterjesse » Mon Dec 06, 2021 11:58 am

Amazing, what fun to play around with microcontrollers and micropython.

Thank you for the support!

Post Reply