Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

won't monitor RPI1031

Status
Not open for further replies.
image.jpg

A clearer view of this sensor.
 
I started from ground zero thinking maybe the internal osc wasn't enabled. It is working
I got the sensor to particularly work. Using Burts code it senses the tilt but it won't monmitor. As I stated before, I can tilt the dang sensor, turn power on and it senses the tilt but that's it. Can tilt different directions and it won't detect. Its stuck on the last tilt reading.
One thing I read was the pull down resistors are 2.2k. At SPARKFUN it was metioned a larger resistor would be better. YES I increased the resistor going to the sensor Vcc. this is maybe where I need to change. The 330 ohm resistor I have is powering the entire board, not just the LED so instead of 5v on the photo-transistors its less. I measured the output voltage on the sensor (S1 and S2 but not much voltage difference. With the low pull down resistors the S1 and S2 outputs are basically grounded and add to that the lower input voltage. Will draw out a schematic. As I mentioned, Sparkfun mentions the resistor values are wrong.
 
here is what I have

I can get 2v only on one of the output pins when tilting in a certain direction.
The pull down resistors are not large enough. Everything I have seen where pull down resistors or pull up resistors are at least 10K.
Could be the reason I get very little change in voltage on both output pins. Low pull down resistor = a grounded connection somewhat.
These are 805? smd resistors. I might have some but not sure.
The present code I have seems to work partially probably due to the low resistors?
Will research further.
The resistors are mentioned in the SPARKFUN comments
 
image.jpg

The software you need is literally 6 lines as I described above. Forget improving it, stop trying to add stuff to it. Make the basic sensor and code work, then do what you want.

Yes, the comments at Sparkfun do suggest the resistors for the LEDs are too low. This won't keep the sensor from working and has nothing what-so-ever to do with your illogical pile of crap code not working.
 
I have been sensing just one output instead of two. YES I can sense just one but it won't change upon tilting.
Will keep working at it. I realize this is simple. I can ground one of the outputs and the leds indicate it.
 
So apparently you didn't read post 20. The RPI-1031 is not so much a tilt sensor as an orientation sensor. Man, I should have learned not to waste my time explaining things to you. And of course, the time spent doing the drawing was a wasted effort as well.

Furthermore, you ignored the advice in post 20 to use the PICkit logic tool to easily test the sensor. You wouldn't want to inadvertently learn anything.

So instead of understanding how the sensor works and spending a few minutes testing it out with the PICkit logic tool, you think it would be better to start ripping parts off the board and randomly changing code that you don't understand in the hopes of finding something that "sorta works, maybe, most of the time if I UNDERSTAND it right??" Oh right, I forgot your famous phrase...."HOPEFULLY it will work, IF it's CODED right." Gotcha. I understand perfectly now.
 
I took the long way around and used two N>O> switches and the code works just fine. YES I read about the logic tool using the PICKIT2 but have never used it. After I get back from Missioula tomorrow I plan on looking into the logic tool just to see what is going on.
I have yet to rip any parts off the board.
My plan while waiting for the tilt switches from adinofruit? I will investigate the sensor I have.
one note after reading the afriono code several times I get the impression that they are adding up the outputs tio derive which led is to be enabled. Right now, using a DMM I only get voltage changes above 1v only on one of the two outputs regardless how I tilt the dang thing.
off to bed, long drive in the morning.
 
So here is the code you need to do what you are trying to do.

Code:
Device = 18f242

Clock = 20

Include ("utils.bas")

Dim S1 As PORTB.5
Dim S2 As PORTB.4

Dim LED1 As PORTA.5
Dim LED2 As PORTB.3
Dim LED3 As PORTC.0
Dim LED4 As PORTA.3

SetAllDigital

Output (LED1)
Output (LED2)
Output (LED3)
Output (LED4)

LED1 = 1
LED2 = 1
LED3 = 1
LED4 = 1

While 1 = 1
    LED1 = S1
    LED2 = S2
    Toggle (LED3)
    DelayMS(500)
Wend

Notice the order of defining the port pins, setting all the analog pins to digital, setting the LED pins to outputs and then defining the initial state of the LED pins.

The state of LED1 and LED2 equals the state of S1 and S2. Close a switch and the LED turns on. Open a switch and the LED turns off. Compare the simplicity of this to the EIGHT compound if/then statements you code uses to accomplish the same result. Also notice that my code is easy to understand; your code is not.

I'm also toggling LED3 each time through the loop with a half-second delay so that I can tell the code is running. This has the effect of making the switch condition display for half a second and not be responsive to changes during that time.

image.jpg
 
Last edited:
LOL we now no how to pass a high on a input to a output nice LOL. Jon is your head hurting from the left side.

I would do something useful like see where the ball is.

Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 4/2/2013                                                       *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18f2420
Clock = 20
include "utils"
dim stateold as byte
dim state as byte 
dim led1 as portc.0
dim led2 as portc.1
dim led3 as portc.2
dim led4 as portc.3
SetAllDigital
input (portb.0)
input (portB.1)
output (led1)
output (led2)
output (led3)
output (led4)
state = 0
stateold = 0
//while true 
state = portb
stateold = (state and $FF)

if stateold = 0 then 
 portc =%00000001 // tells us no switches are on
endif
if stateold = $3 then 
 portc =%00000010 // tells us both switches are on
endif
if stateold = $1 then 
 portc =%00000100 // tells us switch sw1 is on sw2 is off
endif
if stateold = $2 then 
 portc =%00001000 // tells us that switch sw2 is on sw1 is off 
endif
//wend
Just make that in a sub or a function and call it in your main loop or for testing uncomment the while wend
 
Last edited:
LOL we now no how to pass a high on a input to a output nice LOL. Jon is your head hurting from the left side.

True Burt. My head hurts....but it's caused MrDEB's complete and total confusion and inability to code!

And yes, my four lines of code are as simple as can be, but apparently beyond MrDEB's ability to follow simple logic. But those four lines were what MrDEB was attempting to do.

Also, if there are questions about whether and how the sensor works, lets not compound the problem with unfunctional software. Got to have something that works or it's a hopeless task.
 
I wasn't saying anything about your code being simple I was talking about the picture in post 28
There not any thing wrong with the code I posted it will output all four states
And it wasn't for a mine is better it was to pass the time of day
Bored. But I don't see this being useful on a bikers head.
Most bikers that ride at night make sure there light will stay on
And they sure dont want to tilt there head to make it work like you
Pointed out some where here. Now if we fell off the bike and wanted the
Lights to still look upright then maybe just maybe this would be useful

unfunctional software
I hope your not referring to my code it's fully functional if you can hook a pic 18f2420 up with a crystal 20 mhz and place 4 leds on the lower port of portC and hook the tilt sensor on portb 0 and 1.
 
Last edited:
I hope your not referring to my code it's fully functional if you can hook a pic 18f2420 up with a crystal 20 mhz and place 4 leds on the lower port of portC and hook the tilt sensor on portb 0 and 1.


No, no, no. I wasn't referring to your code; I was talking about MrDEB's code!

Unfortunately, MrDEB can't (or doesn't) think his way through the code. Line by line, what happens if the inputs are 0, 1? What happens if they are 1,1? It doesn't take long to spot several errors in his code if you mentally work your way through it.

The point I was trying to make is to start as simply as possible, especially when you are uncertain of the hardware. Once you see it works how you believe it does or figure out how it actually works, then you can expand on the code to do more.
 
After using the logic tool and confirming results with a DMM I found that one of the outputs was not doing anything.All it output was a LOW. I removed the 2.2k resistors, used 10k pull-down resistors and Jons code (I tried Burts but something is not right?) but jons code appears to work. I found that the cylinder inside tends to stick slightly, After tilting I have to tap lightly and the leds change states.
Experimenting by adding two other states so I can have 00, 01, 11, 10,
Trying led1 = s1 + s2. seems o work but not real smooth.
Going to investigate Burts code some more and find out why it doesn't run.
in one of the codes from an adrino they used (s1 <<1)| s2 //bitwise math to combine the values
 
Well Mrdeb if you didn't get my code to work your doing something wrong it works fine in testing.
tilt.jpg
 
MrDEB, did you get the point I tried to make....this sensor is not designed to measure tilt, it's designed to measure orientation of the board with the board being VERTICAL.
 
Yep it's about the same thing used in phones to rotate the screen
I have a kinde that I've been looking for a Min USB jack I think it has
The same one in it
 
Yes I understand its really not designed to sense tilt. So I ordered 4 tilt sensors that you linked to. Was using some SMD sensors that were very buggie, not real on or off. Just jumped alot. Also used some that work really well but at $17.50 each!!
Just outta curiosity I want to get Burts code working until I get the new sensors.
 
Yes I understand its really not designed to sense tilt....

Somehow, you're not convincing me that you understand what they were designed ffor and the orientation they should be used in...if you don't understand that, you won't get good results.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top