Page 1 of 1

frustration with monkmakes kit and code

Posted: Thu Mar 05, 2015 10:53 pm
by andytwonames
I have just taken delivery of my Pi2 and I'm having a tinker about.

I purchased a kit of components from Amazon. It has 10 projects to build with accompanying python scripts and I have to say I'm disappointed.

The frustration is that the kit tells me what to connect to what and then tells me to run the corresponding python script.

There are no explanations as to what the scripts are doing, nor are there descriptions of how the components are inter-acting.

the first two projects and scripts are simple enough. Blink an LED by switching one of the GPIO pins on and off.

Then we get to project 3 with the RGB LED and controls to give different intensities of each colour.

How does this work? GPIO pins are either on or off... no?

Could some kind soul please look at the code 03_rgb.py and tell me what it's doing?
https://github.com/simonmonk/pi_starter_kit

And... if you have a moment, look at 04_thermometer.py and tell me why I get a negative temperature?

Cheers.

Andy

Re: frustration with monkmakes kit and code

Posted: Thu Mar 05, 2015 11:06 pm
by DougieLawson
The code uses

Code: Select all

pwmRed = GPIO.PWM(18, 500)
which is pulse width modulation. PWM means you switch the pin on and off very rapidly so that over time it's only on for a percentage of the time which means the LED runs at a lower brightness. Reduce the percentage of time when it's on and the LED gets dimmer, increase it and the LED gets brighter.

http://en.wikipedia.org/wiki/Pulse-width_modulation

Re: frustration with monkmakes kit and code

Posted: Thu Mar 05, 2015 11:22 pm
by andytwonames
Ah, righto.

where on earth do I start looking in order to find this stuff out rather than just asking someone who knows?

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 12:27 am
by DougieLawson
Er, that's the whole purpose of this forum, so those of us with twenty years of using Linux can help the folks who only started with Linux last week.

There's a lot of python stuff available with simple Google searches using obvious keywords.

Linux also has some built-in documentation. Try man man & info info as commands in an LXTerminal window.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 8:55 am
by B.Goode
andytwonames wrote:look at 04_thermometer.py and tell me why I get a negative temperature?
The creator of the kit has a website with contact details here: http://www.monkmakes.com/

Perhaps it would be easiest to ask him directly? (And may provide feedback if the instructions or code are unclear.)

(My guess is that maybe the characteristics of the thermistor you have been supplied with are different from the one on which the kit was developed.)

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 9:06 am
by DougieLawson
andytwonames wrote:
And... if you have a moment, look at 04_thermometer.py and tell me why I get a negative temperature?
That's 100% impossible, I don't know what funky hardware you've connected to a_pin = 18 & b_pin = 23.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 9:50 am
by hippy
andytwonames wrote:And... if you have a moment, look at 04_thermometer.py and tell me why I get a negative temperature?
That seems to be using the time to charge a capacitor to determine the temperature sensor resistance so a hardware issue could deliver the wrong resistance and thus the wrong, negative temperature. The manufacturer of the kit can probably give a better explanation.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 10:34 am
by andytwonames
Thanks all for the input. I'll get on to Mr Monk and see what I get back.
DougieLawson wrote: That's 100% impossible, I don't know what funky hardware you've connected to a_pin = 18 & b_pin = 23.
Impossible? Less than a week with the Pi and I've achieved the impossible. I'm doing better than I thought.

I figure it's something to do with line 40 in the script

Code: Select all

 resistance = reading * 6.05 - 939
Next time I have a moment to tinker, I'll try adjusting this. Why 939? who knows?

Supplementary question...

I tried opening the Python window and executing the script from in there but I got error messages (can't recall exactly what - it was 1am and I needed sleep). It was something telling me that I couldn't access the GPIO pins and I should try running as root.

So how would I run from within the Python tool rather than a terminal window? It looks like it would help me to look around the code and see what it's doing.

Now... back to the day job....

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 11:06 am
by Si.
Hi, Simon Monk here, I designed the kit, and I'm sorry you are finding it frustrating.

It would be great if we could bundle in a book that taught you how all this works, but that would make the kit a lot more expensive. So, what you get is 10 cards with breadboard layout and little else. Its good that you want to know how it all works.

The negative temperature is a weird one, when I get a problem like this, I generally pull out all the wires and components and start again. Its also possible, but unlikely, that you have a duff components, in which case we would be happy to replace if you get in touch from the monkmakes website.

There are lots of good resources out there on the Internet for learning Python and tutorials for using GPIO. Maybe work through a few of those and you'll probably find that the code suddenly starts to make sense to you. I did a series of free lessons on Pi GPIO for Adafruit, that may be a good starting point: https://learn.adafruit.com/category/learn-raspberry-pi

The Raspberry Pi does not have analog inputs so, as someone else pointed out earlier, for the projects that use analog sensors like the photoresistor and thermistor, you have to time how long it takes for a capacitor to charge up. Adafruit provides a great explanation of this technique here: https://learn.adafruit.com/basic-resist ... i/overview

I hesitate to say this, but there are also lots of books out about programming the Pi and using GPIO, including my Raspberry Pi Cookbook, which has a few hundred pages in which to explain such things and covers the resistive sensor technique and most of the kit projects.

Hope this helps, and thanks for buying the kit - Si.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 11:12 am
by Si.
I should also say that when you have problems with the projects, there is little point for looking for bugs in the code. Obviously I check everything and we have several thousand people who have the kit and lots of workshops where I've seen all the projects made and the code run fine. I'm sure the code could be improved, but its not buggy.

The problems are nearly always with the wiring (or mixing up the thermistor and capacitor) and very occasionally with a duff component, or something in your Raspberry Pi environment (very old version of RPi.GPIO for example).

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 11:25 am
by DougieLawson
Si,

Your code would be better with some comments. Give an explanation of what that 939 "fudge factor" means, how you derived the value and what happens if you change it. That would make it a better learning resource, else all you've got is a wiring kit that the average 8 yr old can run but they'll learn precisely zero from doing it (apart from identifying pieces & getting the polarities right).

It would also be an idea to suggest some changes to the code, the user changes the code and the exercise is to determine what effect it has on the results.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 11:41 am
by hippy
andytwonames wrote:I figure it's something to do with line 40 in the script

Code: Select all

 resistance = reading * 6.05 - 939
Next time I have a moment to tinker, I'll try adjusting this. Why 939? who knows?
And why 6.05? That line of code was cause of my thinking a hardware issue; if the reading is zero or low then the resistance would be negative, and every calculation based on that could end up negative. Of course negative temperatures exist so it's not impossible to have them, just unlikely for most cases though users of Celsius will see them more often than users of Fahrenheit or Kelvin!

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 11:44 am
by Si.
Hi Dougie,
Your code would be better with some comments. Give an explanation of what that 939 "fudge factor" means, how you derived the value and what happens if you change it. That would make it a better learning resource, else all you've got is a wiring kit that the average 8 yr old can run but they'll learn precisely zero from doing it (apart from identifying pieces & getting the polarities right).
You are right about comments in the code. Especially in the sensor projects and projects that have a UI. This afternoon, I'll put aside some time to put some more explanation in.

Here is a question for the community. Would people be more comfortable, if like so much of Python the resistive sensor code were hidden in a library and you just called get_resistance() ?

I suppose ultimately, what a lot of people would probably like is something like teaching notes on using the kits. I'm a little surprised some teacher hasn't done that. Maybe they have, anyone know of such a thing?

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 11:50 am
by joan
I don't think you need to add much to the code.

A one line comment and perhaps a link would be enough for the RGB (use PWM to vary brightness) and temperature (use resistor/capacitor timing circuit) examples.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 12:56 pm
by PiGraham
Si. wrote:...
The Raspberry Pi does not have analog inputs so, as someone else pointed out earlier, for the projects that use analog sensors like the photoresistor and thermistor, you have to time how long it takes for a capacitor to charge up. Adafruit provides a great explanation of this technique here: https://learn.adafruit.com/basic-resist ... i/overview

I hesitate to say this, but there are also lots of books out about programming the Pi and using GPIO, including my Raspberry Pi Cookbook, which has a few hundred pages in which to explain such things and covers the resistive sensor technique and most of the kit projects.

Hope this helps, and thanks for buying the kit - Si.
Two suggestions Si,

1. include links like that on the project cards so that people who what to know about the techniques can find the info.
2. Provide links to your books, in the kit, on the monkmakes.com site an on the github.

Raspberry Pi Cookbook by Simon Monk
Kindle edition £14.76

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 2:20 pm
by andytwonames
Si. wrote: You are right about comments in the code. Especially in the sensor projects and projects that have a UI. This afternoon, I'll put aside some time to put some more explanation in.

Here is a question for the community. Would people be more comfortable, if like so much of Python the resistive sensor code were hidden in a library and you just called get_resistance() ?
No, don't tuck it all away in libraries. Leave it in the code but please do add comments to explain what it's doing and how. That would be great.

The kit itself is still good value. I doubt I could buy the components for that little.
Si. wrote: I suppose ultimately, what a lot of people would probably like is something like teaching notes on using the kits. I'm a little surprised some teacher hasn't done that. Maybe they have, anyone know of such a thing?
Yeah, I'd like that too.
Si. wrote:I should also say that when you have problems with the projects, there is little point for looking for bugs in the code. Obviously I check everything and we have several thousand people who have the kit and lots of workshops where I've seen all the projects made and the code run fine. I'm sure the code could be improved, but its not buggy.

The problems are nearly always with the wiring (or mixing up the thermistor and capacitor) and very occasionally with a duff component, or something in your Raspberry Pi environment (very old version of RPi.GPIO for example).
I'll give the thermometer another go when I can and report back. I'm happy to go and get another thermistor if needs be. Maplins?

Thanks for taking the time to respond. I'll look out for comments in the code :)

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 3:22 pm
by DougieLawson
Si. wrote: Here is a question for the community. Would people be more comfortable, if like so much of Python the resistive sensor code were hidden in a library and you just called get_resistance() ?
Hi Si,

Do both. Have a library (which can be used for subsequent projects) and have the library code in your main line but commented out, so the people who've never seen python before can get a grasp on why big monolithic blobs of code are a bad idea and why moving commonly called functions to libraries makes for code compactness & re-usability.

I keep every piece of python I write, later programs become a cut'n'paste job.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 5:24 pm
by hippy
Si. wrote:Here is a question for the community. Would people be more comfortable, if like so much of Python the resistive sensor code were hidden in a library and you just called get_resistance() ?
Different sections of the community have different needs and desires. Some will simply want to use the temperature, some will want to know how to determine a temperature.

Most who are interested in using the temperature in an application would probably prefer a library which exposes a usable TemperatureC() or TemperatureF() while others interested in the hardware or electronic side of things would more likely want to see and understand the full 'how to' of charging a cap, measuring the charge time, turning that into a resistance and then temperature. A 'get_resistance() is somewhere between the two.

Providing both is probably the best solution. The 'raw in-line code' can be used to show how it works, while the library can have that nicely encapsulated and include error checking and assertions which can help identify failure modes such as incorrectly fitted hardware where possible.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 6:30 pm
by Si.
Thank you all for your helpful feedback.

The code is now pretty thoroughly commented.

https://github.com/simonmonk/pi_starter_kit

At some point, I'll follow up on some of the other suggestions too.

Si.

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 6:55 pm
by DougieLawson
Well done Si good job

Re: frustration with monkmakes kit and code

Posted: Fri Mar 06, 2015 8:16 pm
by andytwonames
Si. wrote:The code is now pretty thoroughly commented.

https://github.com/simonmonk/pi_starter_kit
Thanks. That's going to be a great help.

Re: frustration with monkmakes kit and code

Posted: Sun Mar 08, 2015 7:18 pm
by andytwonames
Finally got time to have another go.

The thermometer projects report the right temperature. So it looks like I was the duff component.

Most likely, I used the wrong resistances. I know I got the connections right because it did report a temperature somewhere around -40 which went to -35 when I held the thermistor.

Might have a play around to see what I did.

Thanks again to all for the help.