Liberty BASIC Community Forum
« Getting started with the Arduino »

Welcome Guest. Please Login or Register.
Nov 18th, 2017, 9:14pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Getting started with the Arduino  (Read 800 times)
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5560
xx Getting started with the Arduino
« Thread started on: Jun 24th, 2015, 03:31am »

I have tried to simplify this as far as possible. This is a bare bones program that will allow you to talk to an Arduino. As it stands it shows an example of reading analog pin 0.

I will use this framework to post examples of raster scanning and distance mapping.

So have a look and get yourself a tutorial kit.

Code:
   snip
 
« Last Edit: Feb 4th, 2016, 11:52am by Rod » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5560
xx Re: Getting started with the Arduino
« Reply #1 on: Jun 24th, 2015, 03:34am »

This is the current Arduino Sketch, it cant do stepper just yet.

You need to copy and paste this to the Arduino IDE and download it to your board.

Code:
Snip, see wiki
 
« Last Edit: Feb 4th, 2016, 11:53am by Rod » User IP Logged

michael
Guest
xx Re: Getting started with the Arduino
« Reply #2 on: Aug 2nd, 2015, 3:10pm »

I tried to make this turn pin 13 on and wait and then turn it off. I am unsure of which command would do this.
Code:
call send setdigital,13,1
            ti = 100000 *10
            for x=1 to ti
            scan
            next x
            call send setdigital,13,0
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5560
xx Re: Getting started with the Arduino
« Reply #3 on: Aug 3rd, 2015, 02:15am »

The command names are case sensitive so it is SetDigital not setdigital.

Code:
    ' rather than remember numbers lets name our commands
    GetDigital=1
    GetAnalog=2
    GetPWM=3
    GetPing=8
    SetDigital=4
    SetPWM=5
    SetServo=6
    AddServo=0
    DelServo=9
    SetTone=7


    ' open the com port use your own port number
    open "Com4:9600,n,8,1,ds0,cs0,rs" for random as #port

    ' now wait till the port gets opened
    timer 500, [delay]
    wait

    [delay]
    timer 0

    call send SetDigital,13,1
    timer 2000,[done]
    wait

    [done]
    timer 0
    call send SetDigital,13,0

    close #port
    print "ending"
    end


    sub send command,pin,argument
        msg$=""
        msg$=right$("00"+str$(command),2)+","
        msg$=msg$+right$("00"+str$(pin),2)+","
        msg$=msg$+right$("0000"+str$(argument),4)+"*"
        print msg$
        #port msg$
    end sub






    sub quit h$
        close #main
        close #port
        end
    end sub




 


Coding time wasting loops as you copied is frowned upon. Much better to count a variable if you are in a repeating loop like my original code or to use the timer as I show above. In my original code the counter would get increased every 500ms so when it gets to a certain value you can send the off code. The program continues to run and other messages can be exchanged. In the time wasting loop nothing happens bar the program appears to freeze and things will queue and overflow.
« Last Edit: Aug 3rd, 2015, 02:19am by Rod » User IP Logged

michael
Guest
question Re: Getting started with the Arduino
« Reply #4 on: Sep 25th, 2015, 10:03pm »

Rod,
I am trying to translate some work I have completed to Liberty Basic using your interface. I have made a programmable motion sensor with a relay controlled 110 AC light.

There is a way to program the Arduino UNO in Liberty using the EEPROM.. which has 1k of memory you can store long term values while its not connected to Liberty and I am studying that to help.

The PIR Motion Sensor works off 5V, OUT and GND pins.

The 5V connects to the 5V on the Arduino and the GND connects on the GND on the Arduino..

The OUT pin connects to pin 4 and will return HIGH when something moves in front of it (180 degrees front to sides and about 7 meters) (this does not require pulse modulation as the PIR Motion Sensor sets it for you)

Pin4, during boot is set to LOW before the main program starts.


If a pin (like on the PIR Motion Sensor) becomes HIGH, I am guessing the GetDigital command would be used?

If I needed to observe the value of pin 4, but I didn't set it, how would I do this using your program?



« Last Edit: Sep 25th, 2015, 11:39pm by michael » User IP Logged

Dan Teel
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1130
xx Re: Getting started with the Arduino
« Reply #5 on: Sep 26th, 2015, 09:32am »

Are you asking how you will communicate the HIGH/LOW state of pin 4 to liberty basic from the arduino?
« Last Edit: Sep 26th, 2015, 09:32am by Dan Teel » User IP Logged

ZPtr.net
michael
Guest
xx Re: Getting started with the Arduino
« Reply #6 on: Sep 26th, 2015, 11:25am »


Yes.. I need to READ the HIGH or LOW state of a pin on my Arduino. Can you give me an example of me reading a pin if it is HIGH?
thanks
« Last Edit: Sep 26th, 2015, 11:27am by michael » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5560
xx Re: Getting started with the Arduino
« Reply #7 on: Sep 26th, 2015, 12:38pm »

It will depend on whether the PIR latches its output or not. I suspect it won't latch so you will need to read repeatedly in a loop. Short example I posted above for setDigital can be amended to get Digital and setDigital the pin for the light.

i am away from home but the rem statements should have enough info to make the changes you need to the example.

You will need to set the timer to read the pin frequently enough to see the PIR high output.
« Last Edit: Sep 26th, 2015, 12:40pm by Rod » User IP Logged

michael
Guest
exclamation Re: Getting started with the Arduino
« Reply #8 on: Sep 26th, 2015, 2:02pm »

ROD
I respect you. After hours of staring at your rem statements I am sorry for doing this, but I must bring this up:
Quote:
I have tried to simplify this as far as possible.

Quote:
' SetDigital
' Command "04" Pins "00" to "13" Argument "0" or "1"
'
' This will set the pin HIGH or LOW use with LEDs or driver electronics
' to switch relays or pulse motors.

ROD
You have NO examples. All you have is technical information.
A NOVICE programmer will not understand that.
I picked out the SIMPLEST example you had and I was the first to present a snippet on it
You then made an example to help me sort that problem out THANK YOU

Here is how I suggest each one of your rem statement examples should be presented:

Code:
' SetDigital
    ' Command "04" Pins "00" to "13" Argument "0" or "1"
    ' example: call send SetDigital,13,0 ' set pin 13 to LOW
    ' example: call send SetDigital,13,1 ' set pin 13 to HIGH
    'You can use with LEDs or driver electronics to switch relays or pulse motors.
 


Do you have an example that explains how this does its job?
Quote:
' GetDigital
' Command "01" Pins "00" to "13" Argument "0" Response "0" or "1"
'
' The board starts with all pins set to high impedence input and pullup
' resistor off, this means the inputs "float" and pick up stray inductance
' currents, so they will report random high or low if you simply read them.
' So when we issue this command the port is set to input and the pullup
' resistor set high, this forces the pin high, ground the pin via a
' switch/sensor to pull it low.
' This eliminates the "floating" and ensures simple, clean digital reads.



« Last Edit: Sep 26th, 2015, 3:23pm by michael » User IP Logged

Dan Teel
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1130
xx Re: Getting started with the Arduino
« Reply #9 on: Sep 27th, 2015, 09:09am »

Guessing at what you're trying to do as I dont quite understand what you're saying, here goes.


On the arduino side, you have to either poll or attach an interrupt on the pin that is connected to the state of the motion detector if it is as rod says and doesnt latch but instead sends a pulse when motion is detected. Then when you read a high (or low depending on how the sensor works) with digitalRead, or your interrupt gets called by the processor, do a serial.print or equivalent (just dont do a serial.print inside the interrupt as its bad form and timing can get messed up as no other interrupts are called while inside one)

On the LB side, you need to be ready to receive the data with input$(#port,var$) as rod demonstrates in his source code.


Also, in your post you wrote
Code:
The OUT pin connects to pin 4 and will return HIGH when something moves in front of it (180 degrees front to sides and about 7 meters) (this does not require pulse modulation as the PIR Motion Sensor sets it for you)
 


What do you mean no pulse modulation is required? If the OUT pin is a one way line to the arduino then the pin on the arduino should be configured as an input, which would preclude any pulse modulation on that pin at all.

Pulse modulation, from the arduinos aspect, is an output only kinda thing. Its where you switch a pin between high and low (with the pin being configured as an output) to make a waveform. You would use this to talk to a servo, or simulate an analog voltage level by creating a duty cycle that would match it.


And then also, I'm assuming this is how its hooked up? Hard to determine with your posts.
User Image
User IP Logged

ZPtr.net
michael
Guest
xx Re: Getting started with the Arduino
« Reply #10 on: Sep 27th, 2015, 09:55am »

Thanks for responding Dan.

** The point I was making was that Rod did not make examples like I did for his Arduino Interface tool

Here is my video explaining the wiring and the Arduino running the light.

https://youtu.be/Tl5ZLyERrFc

But that is not the problem as I know how the program would be made, because I made it.

But I need to make it work in Liberty, because it allows more elaborate huge programs.

***** The only thing I am asking is for examples for each command Rod made for his interface.. Like I shown on my last post. *****

*** I was pointing out that Rod did not make examples for understanding his Arduino interface commands. His post only gives technical info..

« Last Edit: Sep 27th, 2015, 10:22am by michael » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5560
xx Re: Getting started with the Arduino
« Reply #11 on: Sep 27th, 2015, 1:37pm »

Try this which reads a PIR on pin 4 and outputs on pin 13. It holds the light on for 5 seconds more than the last PIR input.

Code:
    ' rather than remember numbers lets name our commands

    global GetDigital,GetAnalog,GetPWM,GetPing,SetDigital,SetPWM,SetServo
    global AddServo,DelServo,SetTone,Buffer$,lampon
    GetDigital=1
    GetAnalog=2
    GetPWM=3
    GetPing=8
    SetDigital=4
    SetPWM=5
    SetServo=6
    AddServo=0
    DelServo=9
    SetTone=7




    '==============================================================
    'open windows, graphicbox controls or whatever here





    '==============================================================



    ' open the com port use your own port number
    open "Com4:9600,n,8,1,ds0,cs0,rs" for random as #port

    ' now wait till the port gets opened
    timer 500, [delay]
    wait

    [delay]
    timer 0

    ' set the frequency for requesting readings
    Freq=200 '200ms loop

    ' we need an endless loop to pass requests and clear out the serial
    ' buffer since Arduino can only store 64 bytes in its serial output
    ' buffer
    t=time$("ms")+Freq
    while 1
        scan
        if time$("ms")>t then
            t=time$("ms")+Freq
            '=======================================
            'code to send requests goes here
            'call send command,pin,argument

            call send GetDigital,4,0 'request a digital read on pin 4


            '=======================================
        end if
        call getresponse
    wend


    sub send command,pin,argument
        msg$=""
        msg$=right$("00"+str$(command),2)+","
        msg$=msg$+right$("00"+str$(pin),2)+","
        msg$=msg$+right$("0000"+str$(argument),4)+"*"
        'print msg$
        #port msg$
    end sub



    'suck the input buffer dry, keep the remnants of the message if the whole
    'message has not been received
    sub getresponse
        if lof(#port)>0 then
            Buffer$=Buffer$+input$(#port, lof(#port))
            endofdata=instr(Buffer$,"*",1)
            [loop]
            if endofdata>0 then
                'we have a valid end
                dat$=left$(Buffer$,endofdata-1)
                Buffer$=right$(Buffer$,len(Buffer$)-endofdata)
                pin=val(word$(dat$,1,","))
                result=val(word$(dat$,2,","))
                '============================================
                'now print chart or display the reponse
                if pin=4 and result=1 then
                    call send SetDigital,13,1
                    lampon=time$("ms")+5000
                else
                    if time$("ms")>lampon then call send SetDigital,13,0
                end if


                '============================================
                endofdata=instr(Buffer$,"*",1)
                if endofdata>0 then [loop]
            end if
        end if
    end sub



    sub quit h$
        close #main
        close #port
        end
    end sub





 
User IP Logged

michael
Guest
xx Re: Getting started with the Arduino
« Reply #12 on: Sep 28th, 2015, 12:57am »

After examining your code and studying how both your programs work (which was no easy task), this is what I figured:

1) the (while 1) is infinite until the program is forced to end

2) The timer is a counter and not a delay, so it allows the program to process other commands while it monitors the amount of time the light must be on.. ( that is cool)

3) The msg$ sends the command instructions to the Arduino

4) The getresponse reads the Arduino Response and
and assigns a value to PIN and RESULT

5) Arduino responds pin=4 - (the motion sensor pin)

6) And the result=1 ( PIN 4 is HIGH)

7) A static counter counts for 5 seconds and will shut down the light UNLESS additional movement is detected, in which case it keeps resetting.

AMAZING WORK ROD..
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5560
xx Re: Getting started with the Arduino
« Reply #13 on: Feb 4th, 2016, 11:57am »

In an attempt to make the Arduino more accessible to beginners I have added a Wiki tutorial. It probably needs more work so any feedback welcome. I do have stepper motors and a stepper motor driver shield and will at some point add that functionality to the utility.

But as it stands we have absolutely stunningly flexible access to the Arduino board via the community Sketch.

http://lbpe.wikispaces.com/Fun+with+the+Arduino
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls