Remedy for Basic allergy

Axel87

Senior Member
Started this post as a response to a coding post that I couldn't follow.

Maybe someone can help, had similar hurdles?
Having a hard time wrapping my mind around writing code. I have a good grasp on circuit design, components, theory- but when it comes to this part of the project I find myself ,well procrastinating. Would you recommend Logicator for a solution ?
From what I've seen of this program it takes away the "coding" and makes it an easy flow chart.
I have tried to reference the Picaxe manual for questions, but it often leads to more questions..and the cycle continues.
Any ideas, suggestions, further references?

Hobbies- Auto,cycle, home customization/repair. Audio/video/security. Hope these give you a broad image as to what I am building these circuits for
 

Axel87

Senior Member
Would the senior techs recommend the VSM for playing around with circuit designer building while traveling or away from the shop?(obviously breadboard gives you the best experience, but life happens.)
 

westaust55

Moderator
From my knowledge, while there are some users of Logicator on this forum,
The greater proportion seem to use BASIC text based coding in the Programming editor.
I suspect that those using flow charting methods are typically those who are in an early learning phase.
That may have a bearing of the level, quantity, quality and timing to receive feedback to questions.
 

SAborn

Senior Member
The best option is to use basic and learn to crawl before you try to run with writing code, by this i mean setup a few leds and learn to string some basic code together to flash or light each led, you will soon get a feel for basic code and start to move into more complicated code.

This might sound slow to start with but it will become the quickest way to learn, i well expect most here on the forum started out with fashing a few leds with picaxe and developed from there.
 

BeanieBots

Moderator
I fully agree with SAborn.
Flow charting has its place and is often used by 'professionals' for larger programs but at this level it is only really of use for those starting out at an early stage. As can be seen by many of the questions relating to Logicator on this forum, the bulk are when people start to write more complex routines and Logicator begins to get in the way. For anything more complex than flashing an LED you find yourself having to write code within a cell inside Logicator anyway.

BASIC is one of the easiest languages to follow, so you will soon pick it up.

I have mixed thoughts about VSM.
In general, I'm not a lover of simulation software because the easy to calculate bits do not require expensive software and the complex bits are often done wrong by simulation software. (usually because the model is not entered correctly).
For education use, it is absolutely brilliant for demonstrating how a circuit works.
For hobby use, it's fun but an expensive toy.
 
Last edited:

MFB

Senior Member
It could be that your hardware background is making you hesitant about experimenting with code. I certainly had to learn a lot about circuitry before starting to build and test electronics, as its just too easy to make costly mistakes. Coming from a career in hardware it took me a while to realise that these worries need not apply to software experimentation, especially when using simulators. You can certainly gain a lot from an (admittedly unprofessional) 'suck it and see' approach. My advice would be to just get stuck in and when you see that nothing too terrible can happen progress will speed up.

Of course, when you get that contract from NASA for Mars lander software you will need to take a more disciplined approach.
 

John West

Senior Member
I'm a hardware guy as well. One of the best features of the PICAXE is that you can leave the programming cable plugged in and keep modifying and reloading your code quickly to see if it actually does what you want, and in little pieces at that. This immediate feedback about everything you write makes an enormous difference in the ease of programming. Try it. You'll like it.

But start by simply telling it to turn an LED on and off, then expand on your code practice before attempting to write a program to do a complex task. It costs next to nothing to experiment with a PICAXE in order to become proficient. That's the key to learning to program it.
 

Axel87

Senior Member
Thanks for everyone's support and input!
I have been able to follow the manual to get the led to flash and adjust timing ect.
But when I try to move past that point is when I hit the wall.
Using the readadc, ect. It is briefly covered in the manual, but it seems to vague.
Example of my thought process:
Kool, got the led to flash with code. Now what if I add a pot to adjust led timing between flash? Or when you set value for pot, activates x output to relay and switches outputs and led.
Check the manual, alright.
Uhhh..

Sorry for the lack of detail.
At work, had to rush this response.
Thanks again guys!
 

0rphu

New Member
Hi Axel,

most of the time what you'll want to do is get some data, decide what it is and trigger an action based on that, so using a pot to determine the flash interval would go somewhat like this:
0. light the led up
1. read the pot with readadc, the output goes to a variable, say b0
2. evaluate b0 using if /else / elseif or case, based on that use pause to delay the program execution for certain amount of time
3. switch the led off
4. goto 0

I'm not posting code here,the best way to learn is (at least for me in this case) trial and error. I hope it makes sense :)
 

Jamster

Senior Member
In orohu's answer, step 2 is way more complicated than it needs to be, just stick b0 directly into the pause statement. :) If need be you can use maths to scale it up and down :)
 

0rphu

New Member
Indeed it is too complicated, but I wanted to make it somewhat universal and I'm sure everyone will agree that grasping the use of branching (using ifs) in program is vital.
 

Axel87

Senior Member
Hi Axel,

most of the time what you'll want to do is get some data, decide what it is and trigger an action based on that, so using a pot to determine the flash interval would go somewhat like this:
0. light the led up
1. read the pot with readadc, the output goes to a variable, say b0
2. evaluate b0 using if /else / elseif or case, based on that use pause to delay the program execution for certain amount of time
3. switch the led off
4. goto 0

I'm not posting code here,the best way to learn is (at least for me in this case) trial and error. I hope it makes sense :)
Step two, what does the picaxe read?
Is it measuring the resistance or voltage changes?
Thank you for your help
I was also looking for any better reference materials besides the picaxe manual, something with more in depth material?
I sometimes regret starting with a picaxe, I feel the ardunio community is a lot larger and has more material out to help with learning programming.
Thoughts?
 

geoff07

Senior Member
Personally I don't think it gets any simpler than Picaxe (except perhaps Genie, but that is too simple to do much and is aimed at quite young kids). Arduino is more expensive and not necessary for you now.

The hardware and software mindset are different, but software is easy to learn once you get into it. The key concept of software is layers of abstraction - think of your objective and strategy and at the bottom layer use subroutines to hide the hardware detail.

The Picaxe manuals may seem simple, but they are pretty much all you need. For some more examples, try David Lincoln's book (2nd ed) - well worth a read.

For the real detail the Microchip datasheets for the underlying chips give the hard stuff. But whilst interesting, you rarely need them, they just highlight how much work rev-ed have done for you in the Picaxe firmware.

Apart from the action commands like readadc etc, you don't need to learn many instructions to start with.

Do/loop and its conditionals for loops
select for alternative paths
if/else/endif for testing conditions
for/next for repetition
subroutines for hiding detail and for the same code used in multiple places.

will cover most things

--

In step 2 the readadc command is reading the voltage on the pot wiper. It will be between 0v and Vcc. The chip uses a sample and hold circuit to capture it and then it is converted to a byte value 0-255 (1-1023 in a word variable for the readadc10 command) which you can then test (255 == Vcc). Try using it as a simple voltmeter!
 

westaust55

Moderator
Not in the order asked but comments are:

There are no other comprehensive documents/tutorials covering all the PICAXE capabilities other than the Rev Ed PICAXE manuals with links at the top of these forum pages.

While communities for other microcontroller chips may be larger, some are apparently a little "aggressive" to what may be seen as a question where the answer can be found elsewhere.
The alternate languages for some of these other chips will seem equally if not more difficult to get to grips with.
The acronym BASIC says it all... Beginners All-purpose Symbolic Instruction Code.

You regret starting with PICAXE
Why?
Your learning curve with be equal to or harder with many other controller chips.

In the sample code by Orpheus,
Step 1 is reading an analogue voltage as exists at the designated pin.
In simple terms, the voltage range can be from 0 volts to a max being the same as the PICAXE supply voltage. For higher voltages resistors are needed as a potential divider. A value proportional to the analogue voltage is placed in the mentioned variable (eg b0)

Step 2 is then comparing the value with preset values using IF...THEN command to perform other actions depending upon the value in the variable.

You need to experiment with writing small blocks of code.
You suggest you have a greater level of electronics hardware so there should be no problems if the hardware is coherent and the program does not perform as expected. Experimentation is a great learning tool.
 

SAborn

Senior Member
It would seem you are a little lost in the programming, so perhaps some simple code examples for you to play with and reverse engineer might help you.

First tell us what chip you are using and what board setup you have, then we can give some simple code examples to suit, after working through some examples it all might start to become clearer.

Also this allows us to see the code and answer questions that relate directly to any problem.

Another good tool to use for starting out is the "DEBUG" command as this will allow you to see on screen the values in a variable (b0 etc) as you adjust a pot using readadc or other commands, its far easier to understand when you can view the actual data and see how it all works.

So before you give up and kick the cat across the room, step back and tell us what hardware you have and what you want to do with it, then we can work with you to help you advance forward.

For an example if you have a 08m2 chip you could try this little code example, its written as basic as i could so you might be able to follow it.

Code:
#picaxe 08m2

symbol led = 	C.1
symbol resistor = C.2

symbol ADC_value = b0


Main:

	readadc resistor, ADC_value

	if ADC_value > 125 then
	high led
	endif
	
	if ADC_value < 125 then
	low led
	endif

	debug
	
	pause 100
	
	goto main
very simply it will read a pot connected to pin C.2 called resistor, then put the value in variable b0 called ADC_value, if the value is greater than 125 it will light a led connected to pin C.1 called Led, if the value of adc is below 125 then it will turn the led off.
You will also see the debug screen pop up after the download and should see the adc value change as you dial the pot up and down (0 to 255)
 

Axel87

Senior Member
It would seem you are a little lost in the programming, so perhaps some simple code examples for you to play with and reverse engineer might help you.

First tell us what chip you are using and what board setup you have, then we can give some simple code examples to suit, after working through some examples it all might start to become clearer.

Also this allows us to see the code and answer questions that relate directly to any problem.

Another good tool to use for starting out is the "DEBUG" command as this will allow you to see on screen the values in a variable (b0 etc) as you adjust a pot using readadc or other commands, its far easier to understand when you can view the actual data and see how it all works.

So before you give up and kick the cat across the room, step back and tell us what hardware you have and what you want to do with it, then we can work with you to help you advance forward.

For an example if you have a 08m2 chip you could try this little code example, its written as basic as i could so you might be able to follow it.

Code:
#picaxe 08m2

symbol led = 	C.1
symbol resistor = C.2

symbol ADC_value = b0


Main:

	readadc resistor, ADC_value

	if ADC_value > 125 then
	high led
	endif
	
	if ADC_value < 125 then
	low led
	endif

	debug
	
	pause 100
	
	goto main
very simply it will read a pot connected to pin C.2 called resistor, then put the value in variable b0 called ADC_value, if the value is greater than 125 it will light a led connected to pin C.1 called Led, if the value of adc is below 125 then it will turn the led off.
You will also see the debug screen pop up after the download and should see the adc value change as you dial the pot up and down (0 to 255)
I apologize for the delay in my response.
New job and working on the other end of my projects has kept me away.
SAborn, you have me intrigued with this post, these practices sound fun and educational!
I currently have a 14m2(w 2 spares;))
As far as what "Board setup" I have, I am confused? Are you looking for a rough schemo? I havent started building my main project circuits yet, as I am still trying to learn the individual component controls(Basic Programing) before trying them all together.
I will build the circuit and input the code you provided and try to get back to you soon.
"So before you give up and kick the cat across the room, step back and tell us what hardware you have and what you want to do with it, then we can work with you to help you advance forward."
The list of components that I have gathered for on project- 24V Stepper, 12/24v Relays, Solar charger(Yet to order panels), 12v battery, Photo-interrupter, Temp sensor, humidity sensor, and (havent researched how yet but I would like to use old android phone for touch control and readout.)
So after that ramble ;) I have alot to learn. But I will start with your circuit and hopefully hear back again
Thank you for your time
 

Axel87

Senior Member
Hi Axel,

most of the time what you'll want to do is get some data, decide what it is and trigger an action based on that, so using a pot to determine the flash interval would go somewhat like this:
0. light the led up
1. read the pot with readadc, the output goes to a variable, say b0
2. evaluate b0 using if /else / elseif or case, based on that use pause to delay the program execution for certain amount of time
3. switch the led off
4. goto 0

I'm not posting code here,the best way to learn is (at least for me in this case) trial and error. I hope it makes sense :)
I will attempt this and get back to you.
Its going to take some time but well see how it goes :)

Although, I should mention to everyone, the class I hated the most in college? Digital Theory. AND/Or/NOR/XNOR gates, Boulign Logic ect.
That made my head spin. lol
Give me a Analog and my scope and Ill entertain myself all day. How does the chip work? Some idea, but mostly I just need the I/O specs lol
 

SAborn

Senior Member
Ok now we know what picaxe you have i have changed the code example given above to better suit the 14m2.

The only changes made is to the pins used, now the LED is connected to pin B.1 and rhe pot to B.2.

Here is the revised example for you to try.

Code:
#picaxe 14m2

symbol led = 	B.1
symbol resistor = B.2

symbol ADC_value = b0


Main:

	readadc resistor, ADC_value

	if ADC_value > 125 then
	high led
	endif
	
	if ADC_value < 125 then
	low led
	endif

	debug
	
	pause 100
	
	goto main

but mostly I just need the I/O specs
As for the pinouts they can be found here in manual 1............

http://www.picaxe.com/Getting-Started/PICAXE-Manuals/

Here is the 14m2 pinouts from manual 1.

14m2 pinouts.JPG
 

Axel87

Senior Member
Apologize for the delay in getting back to this.
completed my project for fathers day, before and after photos attached. (Got the rusted parts washer for 10 buck)
Photo Jun 09, 12 10 24 AM.jpgPhoto May 11, 4 39 09 PM.jpg
I thought about using a picaxe to control the LED's above but Im not familiar enough with the enclosers available out there.
This would need to be a pretty heavy duty box, Water/fuel proof.
Just thought I would share :)
Anyway, Ill plan on trying out this practice tonight and get back to you for the next step!
Thanks again!
 

boriz

Senior Member
Flowcharts are useful enough for consolidating thoughts and ideas. Completely useless as a programming language though.

BASIC stands for Beginner's All-purpose Symbolic Instruction Code. If you ever intend to learn to program, BASIC is a good place to start. I have found something simpler though, which might get you interested enough to play with BASIC. It's called Scratch, and has a very friendly drag and drop interface designed for schoolkids. Free version here. Be sure to read the 'getting started' PDF. It might cure your allergy :)
 

Axel87

Senior Member
Just completed your first exercise. ( also on analog sensors in the manual)

Things I noticed- When I watch the pot on the debug window the values flucuate like crazy, about half of the swipe the led flashes on/off as if the picaxe cannot decide were its at. ( Is this were the readadc10 comes in?)
I have a piezo connected to the PZ out on my board, would this effect anything? or is it just a audible readout of whatever variable value its set to read?

Will continue working on the book till I get another practice!
Thanks guys
 

premelec

Senior Member
sounds like noisey pot or signal - all kinds of stuff can be picked up on a high impedance input without any filtering on it - and pots can be defective and wiring loose - so many things to go wrong :) Try to find what makes it stable...
 

LeonR

Member
I'm the otherway around and struggle with the electronics!! :confused:

The coding should make more and more sense the more you use it.
Generally if/then statements and loops should be enough for the basis of most code in my opinion so once you have this sussed then you will be well away :cool:
 
Top