File Exchange

image thumbnail

ADLX345 i2c Driver for Arduino Mega

version 1.1.0.0 (132 KB) by Eddy Trinklein
This is a driver for the analog devices ADLX345 triaxial acceleration and an Arduino mega.

20 Downloads

Updated 01 Apr 2013

View License

This driver utilizes the Arduino i2c libraries from version 1.0 and driver architecture found from various sources on the web. It configures the sensor to +/- 4 G's at 100 Hz. The data sample rate is set to 0.05 second period via the S-Function builder update rate. Additional settings are described in the manual.

For additional information and tips please look at the excellent description by Giampiero Campa.

http://www.mathworks.com/matlabcentral/fileexchange/39354

Comments and Ratings (10)

Can the code be run on arduino UNO. I have run the program using Arduino UNO and it is executed without any errors.But I am not receiving any output on the scope. I have tried to understand the code and there doesn't seem any part making it specific for arduino Mega.

Problem solved, I made a "Utility" folder in my working folder, now works 100%.

Not sure where I am going wrong,every time I get this :

=== Simulation (Elapsed: 22 sec) ===
### Starting build procedure for model: Arduino_ADLX345_driver
Error:C:/ProgramData/MATLAB/SupportPackages/R2017b/3P.instrset/arduinoide.instrset/arduino-1.8.1/hardware/tools/avr/bin/avr-gcc -std=gnu11 -c -g -w -ffunction-sections -fdata-sections -MMD -DARDUINO=10801 -MMD -MP -MF"Arduino_ADLX345_driver.dep" -MT"Arduino_ADLX345_driver.o" -Os -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO_AVR_ADK -DARDUINO_ARCH_AVR -D_RUNONTARGETHARDWARE_BUILD_ -D_ROTH_MEGA2560_ -DMODEL=Arduino_ADLX345_driver -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DON_TARGET_WAIT_FOR_START=1 -DEXT_MODE=1 -DINTEGER_CODE=0 -DMT=0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DTID01EQ=0 -DEXIT_FAILURE=1 -DEXTMODE_DISABLEPRINTF -DEXTMODE_DISABLETESTING -DEXTMODE_DISABLE_ARGS_PROCESSING=1 -DSTACK_SIZE=64 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DRT -DMW_TIMERID=5 -DMW_PRESCALAR=256 -DMW_TIMERCOUNT=59286 -DMW_SCHEDULERCOUNTER=1 -D_RTT_BAUDRATE_SERIAL0_=9600 -D_RTT_BAUDRATE_SERIAL1_=9600 -D_RTT_BAUDRATE_SERIAL2_=9600 -D_RTT_BAUDRATE_SERIAL3_=9600 -D_RTT_ANALOG_REF_=0 -DEXT_MODE=1 -DINTEGER_CODE=0 -DMT=0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DTID01EQ=0 -DON_TARGET_WAIT_FOR_START=1 -DEXIT_FAILURE=1 -DEXTMODE_DISABLEPRINTF -DEXTMODE_DISABLETESTING -DEXTMODE_DISABLE_ARGS_PROCESSING=1 -DSTACK_SIZE=64 -DRT -DMODEL=Arduino_ADLX345_driver -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -IC:/Users/John/Desktop/NEWFOL~2 -IC:/Users/John/Desktop/NEWFOL~2/Arduino_ADLX345_driver_ert_rtw -IC:/MATLAB/R2017b/extern/include -IC:/MATLAB/R2017b/simulink/include -IC:/MATLAB/R2017b/rtw/c/src -IC:/MATLAB/R2017b/rtw/c/src/ext_mode/common -IC:/MATLAB/R2017b/rtw/c/ert -IC:/MATLAB/R2017b/toolbox/coder/rtiostream/src/utils -IC:/ProgramData/MATLAB/SupportPackages/R2017b/3P.instrset/arduinoide.instrset/arduino-1.8.1/hardware/arduino/avr/cores/arduino -IC:/ProgramData/MATLAB/SupportPackages/R2017b/3P.instrset/arduinoide.instrset/arduino-1.8.1/hardware/arduino/avr/variants/mega -IC:/ProgramData/MATLAB/SupportPackages/R2017b/3P.instrset/arduinoide.instrset/arduino-1.8.1/libraries/Servo/src -IC:/ProgramData/MATLAB/SupportPackages/R2017b/toolbox/target/supportpackages/arduinotarget/include -IC:/ProgramData/MATLAB/SupportPackages/R2017b/toolbox/target/supportpackages/arduinotarget/scheduler/include -IC:/ProgramData/MATLAB/SupportPackages/R2017b/toolbox/target/supportpackages/arduinobase/include -IC:/ProgramData/MATLAB/SupportPackages/R2017b/3P.instrset/arduinoide.instrset/arduino-1.8.1/hardware/tools/avr/avr/include/avr -IC:/ProgramData/MATLAB/SupportPackages/R2017b/toolbox/target/shared/externalmode_daemon/include -o Arduino_ADLX345_driver.o Arduino_ADLX345_driver.c
In file included from C:/ProgramData/MATLAB/SupportPackages/R2017b/toolbox/target/supportpackages/arduinotarget/scheduler/include/arduinoAVRScheduler.h:9:0,
from MW_target_hardware_resources.h:6,
from Arduino_ADLX345_driver.h:19,
from Arduino_ADLX345_driver.c:2:
C:/Users/John/Desktop/NEWFOL~2/Arduino.h:56:22: fatal error: compiler.h: No such file or directory
#include "compiler.h"
^
compilation terminated.
gmake: *** [Arduino_ADLX345_driver.o] Error 1
The make command returned an error of 2
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.
### Build procedure for model: 'Arduino_ADLX345_driver' aborted due to an error.
Error:Error(s) encountered while building "Arduino_ADLX345_driver":
### Failed to generate all binary outputs.

Claudio

Hi Eddy,
I tried to use your example (that works perfectly :) ) like a template to compile a different code that uses some additional cpp library, but when I try to compile on ArduinoMega it returns an error. There is something else that I have to take in account in add to your "readme" file? Thank you in advance.

Below the error log:
The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
The build failed with the following message: "E:/Programmi/MATLAB/SupportPackages/R2013b/arduino-1.0/hardware/tools/avr/bin/avr-gcc" -I"F:/doc meccanica/Arduino/Test_simulink_compiling/Arduino_ADLX345_driver_v1_rtt" -I"F:/doc [...]

Dylan

Addie,

Have you tried a different compiler?

Thanks,

Ed

Hi Eddy:

I have this problem on downloading your model to my ArduinoMega:

The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
The build failed with the following message: "C:/MATLAB/Targets/R2012a/arduino-1.0/hardware/tools/avr/bin/avr-gcc" -I"C:\Users\user\Downloads\ADXL345_driver_v1\Arduino_ADLX345_driver_v1_rtt" -I"C:\Users\user\Downloads\ADXL345_driver_v1" -I"C:\Program Files\MATLAB\R2012a\extern\include" -I"C:\Program Files\MATLAB\R2012a\simulink\include" -I"C:\Program Files\MATLAB\R2012a\rtw\c\src" -I"C:\Program Files\MATLAB\R2012a\rtw\c\src\ext_mode\common" -I"C:\Program Files\MATLAB\R2012a\rtw\c\ert" -I"C:\MATLAB\Targets\R2012a\arduino-1.0\hardware\arduino\cores\arduino" -I"C:\MATLAB\Targets\R2012a\arduino-1.0\hardware\arduino\variants\mega" -I"C:\MATLAB\Targets\R2012a\arduino\include" -I"C:\MATLAB\Targets\R2012a\arduino-1.0\libraries\Servo" -I"C:\Program Files\MATLAB\R2012a\rtw\c\src\ext_mode\serial" -mmcu=atmega2560 -std=gnu99 -Wall -Wstrict-prototypes -gstabs -Os -D"MODEL=Arduino_ADLX345_driver_v1" -D"NUMST=1" -D"NCSTATES=0" -D"HAVESTDIO=" -D"ONESTEPFCN=0" -D"EXT_MODE=1" -D"TERMFCN=1" -D"MAT_FILE=0" -D"MULTI_INSTANCE_CODE=0" -D"INTEGER_CODE=0" -D"MT=0" -D"TID01EQ=0" -D"F_CPU=16000000" -D"_RUNONTARGETHARDWARE_BUILD_=" -D"_ROTH_MEGA2560_=" -D"_RTT_NUMSERVOS_=0" -D"EXIT_FAILURE=1" -D"EXTMODE_DISABLEPRINTF=" -D"EXTMODE_DISABLETESTING=" -c -x none ./HardwareSerial.cpp ./Print.cpp ./WInterrupts.c ./WMath.cpp ./WString.cpp ./new.cpp ./wiring.c ./wiring_analog.c ./wiring_digital.c ./io_wrappers.cpp ./rtiostream_serial.cpp ./ext_svr.c ./ext_work.c ./updown.c ./ext_serial_pkt.c ./ext_svr_serial_transport.c ./rtiostream_serial_interface.c ./ADXL345_driver_v1_wrapper.cpp ./Arduino_ADLX345_driver_v1.c ./ert_main.c
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
./io_wrappers.cpp: In function 'void Serial_read(int, int, uint8_t*, int*)':
./io_wrappers.cpp:40: warning: 'libFcnOutput' may be used uninitialized in this function
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
cc1plus.exe: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
./rtiostream_serial.cpp: In function 'int rtIOStreamOpen(int, void**)':
./rtiostream_serial.cpp:28: warning: unused variable 'init_complete'
./ext_svr_serial_transport.c: In function 'ExtProcessArgs':
./ext_svr_serial_transport.c:247: warning: format '

The build process will terminate as a result.

Please help me on this. I have followed your steps in 'readme' file. But this error occurred. Your model is useful for my project to connect other chips with my ArduinoMega

Hello, I tried to build the slx file in simulink but the error in s -function'Arduino_ADLX345_driver_v1/S-Function Builder1':S-function'ADLX345_driver_v1' does not exist.
Could you please help me? Thanks,

Efri

Phil,

If you could provide more info on where you run into problems I might be able to help you. It sounds like you've used this example to build a custom LCD driver? Awesome, I would love help.

Thanks,

Ed

phil

hey man great work. i am trying to follow your steps but i keep getting errors when trying to upload my driver (lcd driver)...it would be amazing if you could maybe do a screenrecord of the process and put it on youtube...i cant figure out what i am doing wrong...thanks!

Updates

1.1.0.0

Two code revisions in the model outputs section due to compile errors, caught before anyone downloaded this file. Revision level kept the same to match readme file.

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor