Confusion with ULN2803 and IR sensor power

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#11 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 6:23 pm Yes, technically it is incorrect, it is a 'darlington driver array'

One of its many features is certainly for driving inductive loads - such as relays - as it has the built in flyback diodes on the 'com' rail so saves adding one for each inductive load. You can see on the list of 'suggested' uses it can be used for anything really.
I found a box of 50 genuine toshiba ones in a box under the bench the other day, I bought them in the UK and had them on the boat so they have to be over 20 years old now. Amazing device. Really useful.
For AM, for the smaller hardware boards, I would stop buying anything apart from the PICO as they are just light years ahead of the competition and cheaper. If you ever play around with the arduino IDE they are truly awesome bits of kit also. The leonardo, nano, micro etc are history really. Crazy cheap.

Here's a bit from the thing you don't like - the datasheet haha - well, one of them, there are loads but they are all basically the same This datasheet is actually from TI.
Image1.jpg
I googled PICO. Are they more like Raspberry PI controllers?

I see that AM has the option to flash a Raspberry PI Pico. Should I get one of those and educate myself?
image.png
Last edited by Kaellis991 on Sun Aug 14, 2022 6:44 pm, edited 2 times in total.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#12 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 6:33 pm oh, for the code, I was thinking it was arduino, but its lua lol,
in the function that receives 'state' you can remove the print for testing (or leave it) and add (in Air Manager)

log(state)
state = state ~ 1
log(state)

You can remove the 'log()' s later as well after debug

the state = state ~ 1 simply inverts the 'state' so if its a 0 its now a 1 and visa versa

it is just a bitwise exclusive or (XOR)

it saves using if else etc..

Joe
Can you explain that it layman's terms? I cant correlate what you are saying with the code that I have.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#13 Post by jph »

Kaellis991 wrote: Sun Aug 14, 2022 6:36 pm
jph wrote: Sun Aug 14, 2022 6:23 pm Yes, technically it is incorrect, it is a 'darlington driver array'

One of its many features is certainly for driving inductive loads - such as relays - as it has the built in flyback diodes on the 'com' rail so saves adding one for each inductive load. You can see on the list of 'suggested' uses it can be used for anything really.
I found a box of 50 genuine toshiba ones in a box under the bench the other day, I bought them in the UK and had them on the boat so they have to be over 20 years old now. Amazing device. Really useful.
For AM, for the smaller hardware boards, I would stop buying anything apart from the PICO as they are just light years ahead of the competition and cheaper. If you ever play around with the arduino IDE they are truly awesome bits of kit also. The leonardo, nano, micro etc are history really. Crazy cheap.

Here's a bit from the thing you don't like - the datasheet haha - well, one of them, there are loads but they are all basically the same This datasheet is actually from TI.
Image1.jpg
I googled PICO. Are they more like Raspberry PI controllers?

I see that AM has the option to flash a Raspberry PI Pico. Should I get one of those and educate myself?

image.png
Yeah, get a couple for playing, as said, the nano, uno, micro,leonardo etc etc are all dead and obsolete now as far as I am concerned. I have stacks of nanos as I used to buy them 10 at a time when they were less than a euro each from china, those days are gone. They are still really good but I wouldnt buy any new ones. The pico is simply awesome for what it is and the price is 4 dollars. You can get one with the pins soldered if you dont want to solder them. Yes, AM supports the pico by direct flash. I dont use those parts of AM but it is excellent.
Joe. CISSP, MSc.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#14 Post by jph »

Oh, the code,

yeah, it should look something like -

Code: Select all

-- create output
outp_id = hw_output_add("My output",false) -- I changed this to false for initial state but set it as you want

function input_change1(state)
    log(state) -- pretty output for debug on console - the var state prior to bitwise XOR with 1
    state = state ~ 1  -- exclusive or (bitwise XOR) the state var with 1, this inverts the value of state as state as state is only ever 0 or 1 o start with.
    log(state) -- more pretty output for debug on console - the var state after bitwise XOR with 1
end

-- create input
position_1 = hw_input_add("My input 1", input_change1)

you can remove the log(0s later after testing, they just show you the output of 'state' in the console.

the state = state ~ 1 is a far easier way of writing something like

if state = 1 then state = 0
else state = 1
blah blah

you can either accept it just works lol, or if you like you can look into one of the most useful aspects of coding (for me anyway) and that's operations on 'bits' - bitwise operations, or, Boolean algebra

Here we have a simple XOR - exclusive OR operation,
2 inputs and one output.

if we call the inputs a and b then a can represent the value of state which when passed will either be 1 or 0 depending on the sensor,
b, is our fixed value 1
when we compare state and 1 in an XOR manner then IF EITHER one of them is TRUE (a 1) then the output is true - BUT only 'either' can be true- NOT BOTH !... the not both makes it 'exclusively' 'or'. There is a bitwise OR function as well that gives a 1 output if Either of the bits is 1, if both are 1 it is still a true output and that's a standard 'OR'.. you also have AND, and 'not' AND (NAND) .. there are other combinations which are all great fun when working with binary but thats probably getting too deep too soon as she said haha.

the truth table is

a b out
0 0 0
0 1 1
1 0 1
1 1 0

By having state = state XOR 1 written as state = state~ 1 we do the evaluation of state XOR 1 and place the result (the output of the truth table) back into state
If you follow the logic and the truth table you will see that the value will invert.

Boolean is the mutt's nuts. ;)
Last edited by jph on Sun Aug 14, 2022 7:23 pm, edited 1 time in total.
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#15 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 7:13 pm Oh, the code,

yeah, it should look something like -

Code: Select all

-- create output
outp_id = hw_output_add("My output",false) -- I changed this to false for initial state but set it as you want

function input_change1(state)
    log(state) -- pretty output for debug on console - the var state prior to bitwise XOR with 1
    state = state ~ 1  -- exclusive or (bitwise XOR) the state var with 1, this inverts the value of state as state as state is only ever 0 or 1 o start with.
    log(state) -- more pretty output for debug on console - the var state after bitwise XOR with 1
end

-- create input
position_1 = hw_input_add("My input 1", input_change1)

you can remove the log(0s later after testing, they just show you the output of 'state' in the console.

the state = state ~ 1 is a far easier way of writing something like

if state = 1 then state = 0
else state = 1
blah blah

you can either accept it just works lol, or if you like you can look into one of the most useful aspects of coding (for me anyway) and that's operations on 'bits' - bitwise operations, or, Boolean algebra

Here we have a simple XOR - exclusive OR operation,
2 inputs and one output.

if we call the inputs a and b then a can represent the value of state which when passed will either be 1 or 0 depending on the sensor,
b, is our fixed value 1
when we compare state and 1 in an XOR manner then IF EITHER one of them is TRUE (a 1) then the output is true - BUT only 'either' can be true- NOT BOTH !...

the truth table is

a b out
0 0 0
0 1 1
1 0 1
1 1 0

By having state = state XOR 1 written as state = state~ 1 we do the evaluation of state XOR 1 and place the result (the output of the truth table) back into state
If you follow the logic and the truth table you will see that the value will invert.

Boolean is the mutt's nuts. ;)
I deal with boolean operations in 3D modeling....joining, subtracting 3D objects in CAD.

I plugged your code into my AM hardware.....I'm getting an error message.
image.png

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#16 Post by jph »

Hmm, its already a 'true / false from the hardware function
then you need the long way or pass it to another first which would use as much code probably.
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#17 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 7:34 pm Hmm, its already a 'true / false from the hardware function
then you need the long way or pass it to another first which would use as much code probably.
You are writing in English....but it might as well be Chinese.... ;)

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#18 Post by jph »

Code: Select all

function input_change1(state)
   log(state)
    if state then 
       state = false
    else
       state = true
    end
   log(state)
end
dirty way :lol:

I was presuming a 1 or 0.. there is possibly a neater way with an existing true / false bool.

I dont use the AM hardware functions at all so never get there
Joe. CISSP, MSc.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#19 Post by jph »

Code: Select all

function input_change1(state)
    log(state)
    state = not state  
    log(state)
end
I knew there must be a cleaner way - a bit more boolean, it works this time though :D :roll:
Last edited by jph on Sun Aug 14, 2022 7:55 pm, edited 1 time in total.
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#20 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 7:44 pm

Code: Select all

function input_change1(state)
   log(state)
    if state then 
       state = false
    else
       state = true
    end
   log(state)
end
dirty way :lol:

I was presuming a 1 or 0.. there is possibly a neater way with an existing true / false bool.

I dont use the AM hardware functions at all so never get there
It looks pretty clean to this greenhorn...
Keith did tell me today that there are many things in LUA that the AM developers did not implement in Air Manager. Maybe what you are trying to do is one of those omitted capabilities.

Post Reply