I made the code for the z axis of the accelerometer but i just need some
help on how to adjust it for the X and Y axis. Heres the sample code for
the z axis.
import smbus
import time
def main():
bus = smbus.SMBus(1)
# Power-on the accelerometer, enabling only the z-axis
bus.write_byte_data(0x18, 0x20, 0x24)
try:
while True:
# get z-axis acceleration
tilt = bus.read_byte_data(0x18, 0x2D)
# if it's supposed to be negative
if tilt > 127:
# then convert it to the absolute value of the negative value
tilt = 256 + ~tilt
positive = False
else:
positive = True
# format and print it
pos = tilt / 2
print str(tilt).rjust(6),
if positive:
print 65*' ' + '|' + (pos*'#').ljust(65)
else:
print (pos*'#').rjust(65) + '|' + 65*' '
# sleep
time.sleep(0.1)
except KeyboardInterrupt:
# restore default settings
bus.write_byte_data(0x18, 0x20, 0x07)
if __name__ == '__main__':
main()
I only need an idea for the X and Y axis. Thanks to anyone who can help.
On Sun, Nov 17, 2013 at 4:48 PM, Pedro A. Melendez <[email protected]>wrote:
> Same as python, just write 'node scriptname.js'. I'm not sure if you can
> use run it from cloud9
>
> -Pedro
>
>
> On Sun, Nov 17, 2013 at 3:53 AM, Zain Dar <[email protected]> wrote:
>
>> Thanks for the advice and the links! So, I noticed that the ADXL345 is
>> made in the node-i2c github as a project. There are a number of files in
>> it, so the one that has the code for the working of the accelerometer is
>> the one that is labeled "index.js"? also since I haven't made a code in the
>> .js format, is this done from the terminal or from the cloud9ide? thanks
>> again!
>>
>>
>> On Sun, Nov 17, 2013 at 2:46 AM, Pedro A. Melendez
>> <[email protected]>wrote:
>>
>>>
>>> http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/i2c
>>> https://github.com/kelly/node-i2c
>>>
>>>
>>> On Sun, Nov 17, 2013 at 3:39 AM, Pedro A. Melendez <[email protected]
>>> > wrote:
>>>
>>>> you can use for i2c with python the adafruit library fro the beaglebone
>>>> or if you like to use nodejs there is node-i2c. I used node-i2c to make a
>>>> custom driver for the ds1337 rtc and it worked pretty nice.
>>>>
>>>> -Pedro
>>>>
>>>>
>>>> On Sun, Nov 17, 2013 at 12:25 AM, Zain Dar <[email protected]> wrote:
>>>>
>>>>> Hi, I'm working on two accelerometers, both of them are digital
>>>>> (ADXL345 by sparkfun) and I'm having trouble programming them to display
>>>>> the X, Y and Z axis. I'm trying the code in python first because its alot
>>>>> easier to work with and much faster to learn than C++ but I haven't had
>>>>> much luck in finding tutorials that make sense. Derek Molloys tutorial of
>>>>> the same topic is good but it comes with some problems that I'm unable to
>>>>> solve. He requires to install a number of other packages that are
>>>>> temporarily unavailable online for downloading into my BBB so I have to
>>>>> result to alternate ideas and code examples. Can someone please kindly
>>>>> direct me to a sample code that I can try out?
>>>>> Thanks
>>>>>
>>>>> --
>>>>> For more options, visit http://beagleboard.org/discuss
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "BeagleBoard" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>
>>>>
>>> --
>>> For more options, visit http://beagleboard.org/discuss
>>> ---
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "BeagleBoard" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/beagleboard/YctTkwyFc8g/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>> --
>> For more options, visit http://beagleboard.org/discuss
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "BeagleBoard" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "BeagleBoard" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/beagleboard/YctTkwyFc8g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.