Connect with us

help with picaxe

Discussion in 'Microcontrollers, Programming and IoT' started by robertgzzzt, Nov 5, 2013.

Scroll to continue with content
  1. robertgzzzt

    robertgzzzt

    98
    0
    Jun 26, 2013
    I was browsing around at Sparkfun.com and I discovered this Picaxe 8 pin proto kit . As some of you may remember, I have absolutely no programming skills, but I did manage to program one of the outputs on the chip to blink an LED on for 1 second, off for 1 second using the example code that was given to me in the instructions:

    Code:
    main: high 4
    pause 1000
    low 4
    pause 1000
    goto main
    What I would like to do is have this chip simultaneously blink another LED, obviously on a different output port, to "strobe" ON for, say....20ms, OFF for 500ms and continuously loop (i.e. "goto main"), but being the rookie that I am, I can't figure out how to write the code to achieve this.

    I also need to learn how to fade an orange LED ON when I push a momentary switch, then at a second push of the switch, fade the orange OFF and a blue LED ON (actually it would be a bipolar orange/blue common cathode LED). I know this has something to do with pulse width modulation, but that's as much as I know right now, as I haven't had very much time to study.

    It would be a whole lot easier to just buy the boards I need already assembled and programmed, but I would really like to learn this stuff. If someone could give me a nudge in the right direction, I would really appreciate it. I know I need to study the syntax to learn how to write the code, but the tutorials don't really give good practical examples of how to use the syntax (or at least the one I read didn't).

    I've also purchase this little Bareduino Plus and an Arduino Uno R3 to play around with. I think this is a good little device for programming chips to use on my project boards.
     
  2. robertgzzzt

    robertgzzzt

    98
    0
    Jun 26, 2013
    Ok, I've watch a few youtube vids and I've learned a few things, like how to use labels and symbols, how to use "if then" commands, and "for next" commands. Also how to use and set parameters for analogue sensors, but I still haven't learned how to program the chip so that one press of a momentary switch will control one output, then a second press of the same switch to control another output. I'm pretty sure this is possible because I've seen it in action
     
  3. dncky

    dncky

    15
    0
    Nov 10, 2013
    I code terrible so its a bit of the blind leading the blind here, but as for the switch thing I would do it this way. Id make a counter with the number of options you want to toggle. Lets say you want the button to toggle 2 leds.

    Since we are doing this for 2, it's easy to do it with modulo. So lets say you press the button, you add 1 to the counter. Modulo the counter, if its even, it will return 0, if its odd, it will return one. Based on that, you toggle the LED's. Pseudo code below

    Int Counter
    Int ModuloCheck
    if (ButtonPin==1) //button pressed
    { counter=counter+1) //counter addition
    ModuloCheck=Counter%2 //will return 0 if counter even, 1 if counter odd
    If (ModuloCheck==1)
    Toggle LED1
    else
    Toggle LED2


    Something like this
     
  4. robertgzzzt

    robertgzzzt

    98
    0
    Jun 26, 2013
    Hi dncky, thank you for responding. That looks like code for "Pic" micro controllers. I think Picaxe is totally different. With picaxe, if you use the "if" command, it has to be followed up with "then", like: if 1 = high then xxxxx endif.
     
  5. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    I don't know how to program Picaxe but make sure you have some sort of debouncing stuff in there somewhere or you will end up with spurious results
     
  6. KMoffett

    KMoffett

    719
    73
    Jan 21, 2009
  7. robertgzzzt

    robertgzzzt

    98
    0
    Jun 26, 2013
    Is that like when you throw a switch, let the chip wait a few ms to sorta give the current time to stabilize?


    Yeah, I'm registered at so many web-sites now it's hard to keep up with them all, I was hoping members here might be able to help, but I guess you're right. I suppose picaxe is kinda like playing in the kiddie pool, as microcontrollers go (which is where I belong, lol). Thanks for the reply, I'll give it a looksee. :)
     
  8. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,411
    2,779
    Jan 21, 2010
    If you can't get help elsewhere, post here again. I can help you, but a picaxe forum will probably give you a number of options to choose from and they will be far better equipped to help you.

    Sorry I didn't take notice of your question earlier.

    Don't think that PICaxe are a "kiddy pool" thing. I have a colleague who uses them for many many many serious projects.

    They have limitations, but not as many as you might think.
     
  9. KMoffett

    KMoffett

    719
    73
    Jan 21, 2009
    I agree with Steve. It's not a toy, it's a cheap, viable microcontroller. It may be a hammer compared to a belt-fed, pneumatic PIC nail gun, but it does what it does. I use them at work.

    Ken
     
  10. dncky

    dncky

    15
    0
    Nov 10, 2013
    Yeah, the code I posted will not compile on ANYTHING. Missing all sorts of brackets, semi colons, etc. Just wanted to give you an idea of what you wanted to do.

    As far as ACTUAL code, basic cant be that hard. Can you post some example code with examples(in BASIC) that include io toggle, if statements, and mod operator? That'll help figure it out
     
  11. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,411
    2,779
    Jan 21, 2010
    Although it does help to know how you're driving the outputs
     
  12. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    Not really, I was referring to the way mechanical switches bounce around a lot before actually settling. This bouncing can cause your program to alter states faster than you can see.

    Read this:
    http://www.gooligum.com.au/tutorials/midrange/PIC_Mid_C_1.pdf

    it's always helped me and I actually learned how to program in ASM from this guy. It's not in BASIC but it will help you understand the whole debounce theory
     
  13. KMoffett

    KMoffett

    719
    73
    Jan 21, 2009
    Take a look at the PICAXE manual. "button" is a built-in BASIC command to debounce an input.

    Ken
     
  14. robertgzzzt

    robertgzzzt

    98
    0
    Jun 26, 2013
    I want to thank everyone for responding. I've got a lot of irons in the fire right now. For those of you that don't know, I'm working on building a 1/350 scale model (3 feet long) of the star ship Enterprise from the movie Star Trek: The Motion Picture. I've got two more of this model still in their boxes, waiting to be built after this one.

    Simulating the various lights on that model is what brought me into the world of electronics

    The statement "symbol" is used to rename something. Here's some example code for "if then statements" for an alarm system (I have no idea what a mod operator is)


    Code:
    symbol pressurepad = input1
    symbol siren = 2
    
    main:
    if pressurepad = 1 then high siren endif   [if input 1 is high, then make output 2 high]
    if pressurepad = 0 then low siren endif    [ if input 1 is low, then make output 2 low]
    goto main
    That's just a small example. I'm literally just starting to learn this stuff. I picked up this little bit, plus more, from the four youtube tutorial videos in the links below. The guy explains it in very easy to understand terms, or at least I thought so. I have to admit, my retention isn't very good these days. I think I need to watch them several more times, and these videos are just basic stuff, they don't get as in-depth as I need to go for what I'm wanting to do. I was hoping to maybe learn enough to take some already written code and just modify it to my needs.


    part 1
    part 2
    part 3
    part 4


    As if all of this isn't enough, I've also bought a "Bareduino" and an Arduino to program it with. I found some code that's perfect for the defector dish and photon torpedo controls. The guy just published it right on his blog.

    It's the second code on this page, entitled (enterprise lighting effects)
    http://modelslouch.wordpress.com/arduino-sketches/
     
  15. robertgzzzt

    robertgzzzt

    98
    0
    Jun 26, 2013

    I thought I'd use the same power MOSFET that Kris recommended a while back in that 555 timer thread, the NTD4906N, N-channel power MOSFET, or I'm open for suggestions.

    spec sheet
    http://www.onsemi.com/pub_link/Collateral/NTD4906N-D.PDF
     
  16. CDRIVE

    CDRIVE Hauling 10' pipe on a Trek Shift3

    4,960
    648
    May 8, 2012
    This is mind boggling for me because the Picaxe PDF's are absolutely complete and provide sample code for EVERY command. The rest of the programming will follow all languages, meaning "logical structure".

    BTW: To fade an LED you're going to need an R*C circuit in conjunction with your 08M2.

    Chris
     
  17. KMoffett

    KMoffett

    719
    73
    Jan 21, 2009
    Though I haven't done it, I would guess that you can fade an LED with an 08M2 in software. Use a timed up and down count controlling a PWM output.

    Ken
     
  18. CDRIVE

    CDRIVE Hauling 10' pipe on a Trek Shift3

    4,960
    648
    May 8, 2012
    Ken, we've had many post regarding LED-PWM dimming. LEDs are too fast to take advantage of PWM directly without use of a pump charge scheme.

    He can take advantage of the 08M2's DAC output but that would also require a small filter cap and a HiZ input LED driver.

    Chris.
     
  19. KMoffett

    KMoffett

    719
    73
    Jan 21, 2009
    A R/C on the output! I thought you meant you were using an R/C on the ADC input to establish a varying reference voltage?
    Ken
     
  20. CDRIVE

    CDRIVE Hauling 10' pipe on a Trek Shift3

    4,960
    648
    May 8, 2012
    Nope, that's not what I meant.

    Chris
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-