RPI 1031 Breakout board

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

RPI 1031 Breakout board

Post by MrDEB » Sun Mar 31, 2013 1:53 pm

trying to configure this chip to detect tilt but keep having to reset the pic to determine tilt but then not sure if its right.
Using a Tap-28 board where the LEDs are enabled when port is low.

Code: Select all

Device = 18f2420
Clock = 8
//Config OSC=HS
Include "InternalOscillator.bas"
Include "utils.bas"
//Include "convert.bas"
Dim s1 As PORTC.4
Dim s2 As PORTC.5
Dim led2 As PORTB.3
Dim led1 As PORTA.3
Dim x As Byte
Dim tilt As word 
 
Dim position As Word
dim tilt_pos as integer 
dim index as integer 
Input (s1)
Input (s2)
 
led1=1
led2=1
//tilt_s1 = 2
//tilt_s2 = 3
 
Output (led1)
Output (led2)
SetAllDigital
 
 
 
 
 
While true
 
      If s1 =0 and s2 = 0 Then tilt = 1     // 
      EndIf
      If s1 =1 and s2 =0 Then tilt = 2
      EndIf
      If s1 =1 and s2 = 1 Then tilt = 3
      EndIf
      If s1 =0 and s2 = 1 Then tilt = 4
EndIf
    if tilt = 1 then led1 = 1 
       led2 = 0
      delayms (1000)
      led2 = 1            // leds off
      led1 = 1
    endif
    tilt = 0 
 
    if tilt = 2 then led2 = 0 
       led2 = 0
       delayms (1000)
       led2 = 1            // leds off
       led1 = 1
    endif
    tilt = 0   
    if tilt = 3 then led1 = 0     // both on
        led2 = 0
        delayms (1000)
        led2 = 1            // leds off
        led1 = 1
    endif
     tilt = 0   
    if tilt = 4 then led1 = 1 //and led2 = 1
      delayms(1000)        // blink once
      toggle (led1)
      toggle (led2)
      delayms(1000)
    endif
 
    tilt = 0 
 
 
 
 
     Wend
I need direction. The code at Sparkfun is for adrino but I am using SWORDFISH.
The two outputs on the board (s1, s2) output LOW/ LOW , LOW/ HIGH , HIGH/ HIGH , HIGH/ LOW
using the code from sparkfun as example, I kinda figured just add the outputs to determine tilt.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPI 1031 Breakout board

Post by brad » Tue Apr 02, 2013 11:17 am

I'll have a good look when I get home, but what do you mean exactly where you say that you need to reset the PIC?

It looks as though the sensor out puts 00, 01, 10 or 11 depending on where the little ball is within the sensor (which wall it is on).

I found some info here:
http://bildr.org/2012/02/rpi-1031_arduino/

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPI 1031 Breakout board

Post by brad » Tue Apr 02, 2013 8:10 pm

Just from a short look through your code, there is one problem where you keep making tilt = 0 and then you run an if statement to see if it something other than 0.

for example:

Code: Select all

if tilt = 1 then led1 = 1 
      led2 = 0
      delayms (1000)
      led2 = 1            // leds off
      led1 = 1
endif
tilt = 0
if tilt = 2 then led2 = 0 
       led2 = 0
       delayms (1000)
       led2 = 1            // leds off
       led1 = 1
    endif
    tilt = 0
you check to see if tilt is equal to 1. if it is, then you run the code in the if statement, then you exit the IF statement and straight away make tilt equal to 0. Then you check to see if tilt is equal to 2 (which of course it will not be), so it skips the code in this IF statement then you make tilt equal to 0 again etc...

the key thing here is that whether or not any of the IF statements turn out to be true or not (which the only possible one that could be true is the first one) you are always making tilt 0. so you are ruling out any of the other IF statements.

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: RPI 1031 Breakout board

Post by bitfogav » Wed Apr 03, 2013 3:08 am

Brad's right it will never get past your first IF statement..

just for an example ill probly have an Select statement for this, makes it easier to follow. something this:

Code: Select all

Select tilt
	case 1
	   led1 = 1 
      led2 = 0
      delayms (1000)
      led2 = 1            	// leds off
      led1 = 1

	case 2
       led2 = 0 
       led2 = 0
       delayms (1000)
       led2 = 1            	// leds off
       led1 = 1

	case 3
        led1 = 0     		// both on
        led2 = 0
        delayms (1000)
        led2 = 1            	// leds off
        led1 = 1

	case 4
      led1 = 1 		     //and led2 = 1
      delayms(1000)        	// blink once
      toggle (led1)
      toggle (led2)
      delayms(1000)

End Select
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 3 guests