Help for SERIAL I2C LCD -

Mejlby

Member
Hey guys

I hope someone can give me some good advice.

I have made a timer program where I used an AXE033 SERIAL I2C LCD to display the hours and minutes that I select via the readadc command.

in the program I have written the command:
"if pinB.1 = 1 then goto INDTASTMIN"

and

"if pinB.2 = 1 then goto STARTTIMER

My problem is that it works on the simulation, but when I run the program on my test board then run the whole program WITHOUT waiting for me to type 1 in the command "if pinB.1 = 1 then .....

All inputs "1" and "0 are ignored !!!

See the program and the picture.

I hope someone can tell me what's wrong

Best regards
Mejlby
Denmark
 

Attachments

PhilHornby

Senior Member
If I've interpreted the photos properly, the two switches are connected to the +ve rail and go 'high' when pressed - which seems to match your code.

I'm guessing the Picaxe is hearing noise on the two input pins (because they're floating until a switch is pressed) and misinterpreting it as a switch press. In which case, pull-down resistors to GND are in order.

(Or reverse the logic, let the switches pull the inputs low - and you can then use the built-in 'pullups' in the picaxe and save two components.)
 

Aries

New Member
I'm not sure exactly what you mean, but looking at the start of your program
Code:
main:
    
    readadc C.2,b4                ; read value into b0    
    readadc C.1,b3                ; read value into b0    
    #no_data
init:
        Symbol OLEDtid= B.7                ; Sets Picaxe output Pin
   
        Symbol Baud = N2400                ; Set Baud rate for OLED
        pause 200                       ; wait for display to initialise

    serout OLEDtid,Baud,(254,1)        ; blank the screen
        serout OLEDtid,Baud,(254,128)        ; move to start of first line
       serout OLEDtid,Baud,("SET timer")
        serout OLEDtid,Baud,(254,192)        ; move to start of next line
        serout OLEDtid,Baud,("SET minutter")
   
       pause 200
        goto indtasttim

indtasttim: 

    if b4 < 5 then main    ' if bigger than 5 jump
    if b4 < 25 then tim0    ' if bigger than 5 jump
    if b4 < 50 then tim1    ' if bigger than 30 jump
    if b4 < 75 then tim2    ' if bigger than 60 jump
    if b4 < 100 then tim3    ' if bigger than 90 jump
    if b4 < 125 then tim4    ' if bigger than 120 jump
    if b4 < 150 then tim5    ' if bigger than 150 jump
    if b4 < 175 then tim6    ' if bigger than 180 jump
    if b4 < 200 then tim7    ' if bigger than 210 jump
    if b4 < 225 then tim8    ' if bigger than 240 jump
    
    goto indtasttim
the section of code indtasttim: to goto indtasttim does not allow b4 to change. The comments do not match the code, so it is difficult to know what is supposed to happen. As it is, if b4 is ever greater than 224, you are in an endless loop.
 

Mejlby

Member
If I've interpreted the photos properly, the two switches are connected to the +ve rail and go 'high' when pressed - which seems to match your code.

I'm guessing the Picaxe is hearing noise on the two input pins (because they're floating until a switch is pressed) and misinterpreting it as a switch press. In which case, pull-down resistors to GND are in order.

(Or reverse the logic, let the switches pull the inputs low - and you can then use the built-in 'pullups' in the picaxe and save two components.)

I know I have the wrong color on wires. (sorry )

But even if I do NOT connect "B.1" or B.2 "to + (5V)
then run the program WITHOUT having to press the 2 button.

I can turn off the test table and turn the pontimeter and then the program jumps to for example 8 hours and 10 minutes WITHOUT I have pressed the button "B.1" (5V)

Have you tried running the program ... it works on the simulation


I do not understand ???
 
Last edited:

PhilHornby

Senior Member
I know I have the wrong color on wires. (sorry )
Don't worry about that :)
He also said:
But even if I do NOT connect "B.1" or B.2 "to + (5V)
then run the program WITHOUT having to press the 2 button.
Those switches are effectively electrically isolated from the Picaxe - until you press them. This is why their presence is making no difference. The pins themselves are capable of picking up noise from the environment, which is being (mis)interpreted as an input.

In a nutshell, an input can't be left 'floating'.

See: here, for example for some further explanation.
 

Mejlby

Member
I'm not sure exactly what you mean, but looking at the start of your program
Code:
main:
   
    readadc C.2,b4                ; read value into b0   
    readadc C.1,b3                ; read value into b0   
    #no_data
init:
        Symbol OLEDtid= B.7                ; Sets Picaxe output Pin
  
        Symbol Baud = N2400                ; Set Baud rate for OLED
        pause 200                       ; wait for display to initialise

    serout OLEDtid,Baud,(254,1)        ; blank the screen
        serout OLEDtid,Baud,(254,128)        ; move to start of first line
       serout OLEDtid,Baud,("SET timer")
        serout OLEDtid,Baud,(254,192)        ; move to start of next line
        serout OLEDtid,Baud,("SET minutter")
  
       pause 200
        goto indtasttim

indtasttim:

    if b4 < 5 then main    ' if bigger than 5 jump
    if b4 < 25 then tim0    ' if bigger than 5 jump
    if b4 < 50 then tim1    ' if bigger than 30 jump
    if b4 < 75 then tim2    ' if bigger than 60 jump
    if b4 < 100 then tim3    ' if bigger than 90 jump
    if b4 < 125 then tim4    ' if bigger than 120 jump
    if b4 < 150 then tim5    ' if bigger than 150 jump
    if b4 < 175 then tim6    ' if bigger than 180 jump
    if b4 < 200 then tim7    ' if bigger than 210 jump
    if b4 < 225 then tim8    ' if bigger than 240 jump
   
    goto indtasttim
the section of code indtasttim: to goto indtasttim does not allow b4 to change. The comments do not match the code, so it is difficult to know what is supposed to happen. As it is, if b4 is ever greater than 224, you are in an endless loop.
Hi Aries

In the program "text Comments" I should have changed the text from "greater than to less than"
Only the text is wrong (sorry)

If you run the program you will see that eg "if b4 <50 then tim1" works in the simulation

Mejlby
Denmatk
 

Mejlby

Member
Hi Aries

In the program "text Comments" I should have changed the text from "greater than to less than"
Only the text is wrong (sorry)

If you run the program you will see that eg "if b4 <50 then tim1" works in the simulation

Mejlby
Denmatk

Now I have changed the comment to "LESS THAN "
I think that was what you meant ?


24931
 

Aries

New Member
If you run the program you will see that eg "if b4 <50 then tim1" works in the simulation
Yes, but if b4 is greater than or equal to 225 the tests in indtasttim all fail, so you go back to indtasttim. Because there is nothing in the loop which can change b4 (you never go to main or tim1 etc if b4 is 226, say) you just stay in the endless loop.

This is not the same problem as Phil is explaining, it is just dangerous programming. You might believe that b4 can never exceed 224 but if something unexpected does happen and it gets too big, your program will stop in the loop and tell you nothing. I did wonder if you meant 255 rather than 225 in the tests, but that doesn't change the principle (b4 could be 255), and you should always legislate for the possibility that something unexpected happens. I have genuinely seen industrial code that has the comment "this is always positive", but it failed when it was actually negative.

The other thing which is always worth doing is to include - while you are developing the program, at least - frequent "print statements" - such as
Code:
main:
    
    readadc C.2,b4                ; read value into b0    
    readadc C.1,b3                ; read value into b0    
   sertxd("ReadADC values: ",#b4," ",#b3,CR,LF)

    #no_data
init:
        Symbol OLEDtid= B.7                ; Sets Picaxe output Pin
   
        Symbol Baud = N2400                ; Set Baud rate for OLED
        pause 200                       ; wait for display to initialise

    serout OLEDtid,Baud,(254,1)        ; blank the screen
        serout OLEDtid,Baud,(254,128)        ; move to start of first line
       serout OLEDtid,Baud,("SET timer")
        serout OLEDtid,Baud,(254,192)        ; move to start of next line
        serout OLEDtid,Baud,("SET minutter")
   
       pause 200
        goto indtasttim

indtasttim: 
    sertxd("indtasttim ",#b4,CR,LF)
    ...
    goto indtasttim
 

Mejlby

Member
Hey guys

Thank you so much for everyone's help

My only problem was that I had not set a 10K pull-down resistors to GND on "input" B.1 and B.2

It was PhilHornby who helped me understand that electrical noise can cause problems and this could be solved with a 10K pull-down resistor

Many thanks PhilHornby

Now the program works exactly as I want it to.

Thanks again

Sincerely
Mejlby
From Denmark
 

Attachments

Top