@solid iron I don't think you can do both at the same time since setting it high or low would interrupt the pulse sequence it's trying to read. I assume you mean to do them at different times like one after the other or similar. In that case I think you'll need to deinit() each object before switching to the other one, then deinit() again when you are ready to switch back.
#Using digitalio with pulseio
1 messages · Page 1 of 1 (latest)
Yep you're welcome. I think you got the right idea:
- initialize for digitalio
- set it to HIGH / LOW as desired
- deinit digitalio
- initialize for pulseio
- read pulses
- deinit pulseio
- repeat from top.
I think you would need MOTOR_A_EN.deinit() before pulses = PulseIn(MOTOR_EN_A_PIN)
And then to call MOTOR_A_EN = DigitalInOut(MOTOR_EN_A_PIN) again the next time you want to use it as digitalio.
I think the pin can only be initialized for one type of object at a time. So it can be either a DigitalInOut or a PulseIn. But not both at the same time. If you want to switch from one to the other then you must deinit() the current one before initializing the next one.
You're welcome. I'm always happy to help folks out where I can.
can you share you full current code? I'll take a look.
I think this line:
deinit(digital_pin)
should maybe be this way:
digital_pin.deinit()
But I think you do have the right idea about needing to pass both into the read_pulses() function
@solid iron maybe MOTOR_A_EN and MOTOR_A_EN need to be global declared also insde of init_motor_pwms()?
I'm not sure you need to return the digital_pin here from read_pulses()
return result_pulses, digital_pin
Try like this maybe:
I commented out the B pin one. I would recommend focus on one until it works, then copy the code that works to the other one.
I moved the DigitalIO deinit and setting back up outside of the read_pulses() method. This way it doesn't need to return the new DigitalInOut object. I didn't run this code so it's possible there may be syntax error. Or perhaps some of the variables may still need to be global.