BayleAdvancedProject-p4

From WikiName
Jump to: navigation, search

The library has to be put in your Arduino library folder in order to be used. Be careful, if you do that while the Arduino IDE is running, you have to restart the IDE in order to see the library available in your IDE.

You can find your library folder :

  • on Windows it is likely in “My Documents\Arduino\libraries”
  • on OSX, it is likely in your user “Documents/Arduino/libraries” and similarly on Linux

After having put the library in this folder, you can see it in Sketch > Import Library...

File:Jb-arduino-library.png

ADXL345 library is now available


BE CAREFUL: You have to upload your code without any XBee module connected!

So, I uploaded the test code by bilder at http://bildr.org/2011/03/adxl345-arduino/ using the FTDI board connected to Arduino Fio. I wanted firstly to validate the accelerometer part first.

Here is the patch I used for this purpose:

File:Jb-arduino-patch.PNG


By banging at the left top corner or loading the patch making loadbang banging that for you, you have the umenu fed by serial object (and put in good format by the small subpatcher portHandler)

You can choose the right port. Here I chose the one related to the FTDI board, still connected to the Arduino Fio.

Here is portHandler:


File:Jb-arduino-porthandler.PNG


This takes care of the umeny building.

The subpatcher dataHandler takes care of data coming from serial port.


File:Jb-arduino-dataHandler.PNG


The object sel (abbreviation of select) selects incoming messages and fires a bang to specific output if the message equals the argument corresponding to the specific place of that output. Here, we select 10 or 13. The last output pops out the incoming message if that one doesn’t equal any argument. We also don’t want to consider new line feed (ASCII code 10). This is why we put it as an argument, but we don’t do anything if that one is selected. It is a nice trick to avoid having this message to trigger anything and even to not have it from the right output of [select]

Here, we send all message received from the Arduino, except 10 or 13 to the [zl group 78] object. This latter is a powerful list processing with many features. group argument makes it grouping messages received in a list. The last argument is here to be sure we don’t have too much elements in the list. As soon as [zl group] is triggered by a bang OR the list length reaches the length argument value, it pops out the whole list by its left outlet.

Here, we “accumulate” all messages received from the Arduino, and as soon as a carriage return is sent, a bang is sent and all data are passed to the next object.

We currently have a big list, with all data inside, each value being separated from the other one by a space character (the famous ASCII code 32 we added in the last function of the firmware)

This list is passed to [itoa] object. itoa stands for integer to ASCII. This object converts integer to ASCII characters.

The [fromsymbol] object converts a symbol to list of messages.

At last, after this [fromsymbol] we have our big list of values separated by spaces and totally readable.

Here is the compressed code you can copy-paste into a patcher to see & use this patch

<maxpat>

<code>
----------begin_max5_patcher----------
2125.3oc6bszbihCD9ryuBJN6jROPBXuM6ip1KSUSU6wolJEXq3vrXvKHmIY
lZ9uuBIg4gM1BLlwIUxA6fvH08W2pk5OZ3G2LyNL8YVts0uY8YqYy9wMylIa
pngY5imYuN34EwA4xelc3VNOMwdt5TaB3KdLJY08YrEbU2.87tCL2BibK9BA
J+z5K5qIZoriRC+5stfxNJY65njXFWNHvpFS2xa2ppI9KaXpAzNLHYks0WJN
6Ou4lhOlanxrlkmGrhUJDb1yRkvNJIXAO5oH9KGQQojZ5IDhjeQqonOjlvyi
9tTLkmdO8m5cP8GcT8unaSBVK6V6+HcaVDKytKrYX3RB6aBwaOXYi0x.dveG
jrLtZHOjK.xWZ0wXIl.j.EzqWPChbTWiEowoYpQCbmOAiwPwPTLNBWM.fpNZ
23MNHYcMlkowOM.J5snX1Srr7HwzipAYlcvlM0ZdVsKo.0+pRMny20TThpI3
tlxXOE0taE8al.24BPealRCd1iZqNovReS4kVZTvNRGUGOkQgpldRcpPIgWw
p3zE+KSZE.kMltgkDkrIikyR3Absbr6zKYODrMle+gMoMO+CAKXcdwcXIlYu
JKZYZRgXz3ZKZtb.E9bJmLRc0Q9KRB1bfKNWnIayCCxJP1vXVsocBG9zz3lm
ZmwTLuIHIZc.mwiThKBrqSiVuIKJg2XfXIAh93w7EYowwM5J0Yd5.mYovduf
8snk7Gk8UcvT7yi1TZDr2gQKiVwx4MaiGrJuYKMh1W2Qrd.gFser.CMCN7PV
557WVGlFW+zGL5fzR4SK9pv+SbfaMyV63C96T+VgHH0GnCEkn6o96O8+CYQA
Mj7tBkNqLbpdh13ijQ7z.yvPW4pqNfgigtchg3KAFJmcLQv32isVkktcikqm
YnIV4QBGNZBAcBmnNgSzY3RNeBcKyYwh0xEvjQnIUtKPB9L.S5.7MwCGLkai
bd02iKvJEdiPNIvgHke1.3puAIXmvCvnotcL4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QWZ00mdEotHiIBmrmq6urxw0sOx70R435Z5Te7.qSUM2k.0CUpl6x5Godf
ozS27o+BJUW2K7bKn6UzTKHw3pF28bTWOp9QjQ++uST6qThZYEOgQxxPwJmE
KL.oGiQRmlO23jA8LRisulXnsKjYSZrXd2Jqr.Ny5nE.MU8DJqR1EODRZIWU
HhX7BONw8HXkJi8GhO.np6yDJAmkcuhGu5pnAnAZnbPO+bdCLvSWsJlYv6R.
mJbxw6vuMIHzQBJfGmx8AnlaESL1drnAkOBpmQs+SbGI0GafmPDmsVuLl8uG
ukwSS4Od6m9yOb6+7RxhBeh4EeTcpOltjsdW6ayCUwKu8CT.7u9zGwU2Jitb
xpUDb8D8O86rDUvFkS1wekkPuNeiknn4+XAZptSKDv.dUk37p5MURbZvRE83
m.QTlbWzPlu4M.WgdAIC2MoCXQuGk.Q5C.fkmHgFvoC8BczaQYH20Tn4uEW7
v9HHs39kh7P9Hp9NmBnNi9SkTYDkFXqb.ZRWjBpam4fFv2KigFEKUGIKzn5j
1OMg8RQPfph7BHRuTLr7+qFj14GrmehoBOwaDj9QTbbMQb.0SJ+xJOlXbISH
93Xf7.mLwwAXB731OmejXaPjhUh0KNqpOfFGAo5cNeniPpcKpeneQdWj4Ms7
AGlgnkhqEYjdSgPU87z3HH1s7ArgnO5RnbifSVa9S0ViFhO5xH9HhAxuKXxl
kXj7T7NgahBpg.lFTaZjGnASkblNyEz.zokI0bwQsaiV0gUgjzp9qZU6U6W2
UcUyUhw4m27+.s5fPS.
-----------end_max5_patcher-----------
</code>

</maxpat>

I used this patch to check if everything was fine.

The previous Arduino test code worked fine and as soon as I tap the accelerometer, double tap it, or let it without movement, the Arduino Fio informs me via Serial connection via Max6 and let me know his current state.

I decided to not go further and calibrate anything for now because I wanted to put it in its box to really test in real conditions.

Previous: Building and debugging Next: Xbee Setup