some modules: PID, pulse density mod, MAX6675,...

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
Post Reply
Beau
Posts: 13
Joined: Sun Oct 26, 2014 1:04 pm

some modules: PID, pulse density mod, MAX6675,...

Post by Beau » Wed Oct 29, 2014 8:09 pm

Hi all,

I implemented a little PID controller and associated modules. If anyone would be interested, the code is up on github https://github.com/B3AU/micropython

for now it contains code for these things:

-PID: a PID feed-back loop
-MAX6675: thermocouple measurement chip (discontinued, will add code for the replacement soon)
-PDM: pulse density modulator, used to control a heater using an SSR. Has some benefits over PWM.
-lcd: sparkfun serial graphical lcd 'backpack'
-FIR: finite impulse response, moving average, smoothing class
-rotary: rotary encoder lib

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: some modules: PID, pulse density mod, MAX6675,...

Post by dhylands » Wed Oct 29, 2014 10:57 pm

Cool - I've been thinking of making a reflow oven using micropython as the temperature controller.

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

Re: some modules: PID, pulse density mod, MAX6675,...

Post by pythoncoder » Thu Oct 30, 2014 7:41 am

@Beau There's some useful code there. I hope you don't mind a couple of constructive comments. Have you considered augmenting the FIR code (perhaps by means of a subclass) to handle a coefficients array to build a generic FIR filter?

Regarding the rotary encoder class, it might be worth using the exclusive or operator which avoids the conditional statements in the callbacks. See my
http://forum.micropython.org/viewtopic. ... =368#p1999

Regards, Pete
Peter Hinch
Index to my micropython libraries.

Beau
Posts: 13
Joined: Sun Oct 26, 2014 1:04 pm

Re: some modules: PID, pulse density mod, MAX6675,...

Post by Beau » Thu Oct 30, 2014 9:58 am

Of course I don't mind. That's mainly why I share the code :)

I like that use of the OR operator and I'll include it over the weekend.

The coefficients seem like a good idea as well. Would be easier if I could just use floats though but the byte array doesn't seem to support that at the moment. Floats would also allocate memory and a FIR is probably more useful if you can use it as a callback from an interrupt.

I can't seem to find any information on how the uPy bytearray implementation differs from the CPython one? Would be useful to include the difference in the wiki https://github.com/micropython/micropyt ... Difference

User avatar
JonHylands
Posts: 69
Joined: Sun Dec 29, 2013 1:33 am

Re: some modules: PID, pulse density mod, MAX6675,...

Post by JonHylands » Thu Oct 30, 2014 1:33 pm

I have C code that implements via a finite state machine, a reflow oven controller here: https://github.com/dhylands/projects/tr ... eflow-oven

Its pretty simple, and it works great - I've built 100's of boards with my oven. Shouldn't be too hard to convert to python.

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

Re: some modules: PID, pulse density mod, MAX6675,...

Post by pythoncoder » Thu Oct 30, 2014 6:00 pm

@Beau Re coefficients I agree that the FIR code is most likely to be used in an interrupt service routine. This means it's best (well, mandatory as I understand it) to avoid floats and to ensure that the results of the multiply and add don't exceed 30 bits and cause Micropython to do a heap allocation. For real world values derived from sensors this leaves plenty of leeway but the user does need to understand the issues. Such is life ;)

Regards, Pete
Peter Hinch
Index to my micropython libraries.

Post Reply