Arduino will measure these sensors values and send data to labview using serial communication. I have used this example code to send values of temperature, humidity and light sensor to arduino. From Arduino to labview. You can use this code for checking purpose.
I have a string : ':0100000035' that I sent from Android to Arduino via bluetooth, In Android the CRC of this string is : E9601FB
In my sketch the CRC calculation function is :
the reading loop constructs a char array :
char[11] bufferline
bufferline = ':0100000035'
but when I print the CRC
Serial.println(crc_string(bufferline), HEX);
it gives : F1D51E33and if I do like this : Serial.println(crc_string(':0100000035'), HEX);
it gives the right CRC : E9601FBAm I missing anything ?
Thanks
HoussemHoussem
1 Answer
The crc_string function computes the CRC of an array of bytes until it finds a 0 byte. When you define the bufferline variable, you define it as size 11, not giving room for the 0 of your target string, so the function crc_string will continue scanning the memory after bufferline until it finds a 0 in memory... To solve the problem, define the variable bufferline as size 12 or more.
gugaguga
Not the answer you're looking for? Browse other questions tagged javaandroidc++arduinocrc32 or ask your own question.
Introduction
The Amulet UART communication library for Arduino simplifies the communication between Arduino and any of the Amulet display modules. Amulet has developed it's own CRC based full-duplex serial communication protocol. A typical message packet looks like:
The library abstracts out the having to learn various opcodes, the complexity of packetizing the communication and calculation of CRC. With this library, Arduino just needs to assign certain Amulet defined variables, and the variables will be read by the Amulet display automatically. A serialEvent() call is used to update the state machine, so when there is communication on the serial BUS, the library does its 'magic'.
If you want to know in detail how the Amulet protocol works, you can look at the source in the library. The code is well documented with comments, to make it easy to understand.
'Arduino Amulet UART Communication Library' is licensed under Lesser General Public License(LGPL Version 2.1).
Installation
To use the Arduino Amulet UART Communication Library:
- Go to http://github.com/AmuletTechnologies/AmuletLCD, click the Download ZIP button and save the ZIP file to a convenient location on your PC.
- Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, usually AmuletLCD-master.
- Rename the folder to just AmuletLCD.
- Copy the renamed folder into the libraries folder under your Arduino installation directory.
Examples
The GEMstudio project files for these examples can be found in the extras folder of the library.The following examples are included with the Amulet communication library:
Blinky_GUI - Arduino as Slave.
A slider GUI on the Amulet display is used to control the blink rate of the onboard LED of the Arduino Uno. The display passes the value to variable, AmuletWords[0]. The range of values go from 0 to 500. The Arduino updates AmuletWords[0] as the slider changes.
Button_GUI - Arduino as Slave.
A check box GUI on the Amulet display in the form of an on/off switch controls the state of the onboard LED of the Arduino. The byte value, either 0x00 (off) or 0x01 (on) gets communicated to Aduino, within the variable, AmuletBytes[0]. That same byte gets read back by an ImageSequence widget on the Amulet display to mirror the output of the Arduino's onboard LED.
ReadPOT_GUI - Arduino as Slave.
The values of a POT is read by Arduino using the analog pin 0 (A0) and this value is communicated to the Amulet display by the assignment of AmultWords[0].
The return value of analogRead ranges from 0 to 1023. This is reflected in the min and max parameters of the Bargraph Widget in the corresponding GEMstudio demo.
BlinkWithoutDelay - Arduino as Master.
The interval which the onboard LED blinks is determined by the value of an InternalRAM word variable. This is similar to Blinky_GUI, except that in this case, the Arduino is the master so it will request the variable from the Amulet module and wait for a response. This uses the stock BlinkWithoutDelay example, adding a second task in the main loop. The first task blinks the LED as some interval. The second task updates that interval with the value returned from the Amulet module.
GEMstudio Software
Amulet offers free software to program the Amulet modules. The software says it is a trial version, but is fully featured for GUI projects under 5 pages. You just need to register on the website. Free GEMstudio.