This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void getGyroValues() | |
{ | |
timerReading = micros() - dt; | |
byte xMSB = readRegister(L3G4200D_Address, 0x29); | |
byte xLSB = readRegister(L3G4200D_Address, 0x28); | |
x = ((xMSB << 8) | xLSB); | |
byte yMSB = readRegister(L3G4200D_Address, 0x2B); | |
byte yLSB = readRegister(L3G4200D_Address, 0x2A); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void writeRegister(int deviceAddress, byte address, byte val) | |
{ | |
Wire.beginTransmission(deviceAddress); // start transmission to device | |
Wire.write(address); // send register address | |
Wire.write(val); // send value to write | |
Wire.endTransmission(); // end transmission | |
} | |
int readRegister(int deviceAddress, byte address) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#define DEBUG | |
#include <Wire.h> | |
#define CTRL_REG1 0x20 | |
#define CTRL_REG2 0x21 | |
#define CTRL_REG3 0x22 | |
#define CTRL_REG4 0x23 | |
#define CTRL_REG5 0x24 | |
// Declare L3G4200D address |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int a=0; | |
void setup() | |
{ | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
serialRoutine(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% XBee expects the end of commands to be delineated by a carriage return. | |
xbee = serial(port,'baudrate',9600,'terminator','CR','tag','Quad'); | |
set(xbee, 'TimeOut', 5); %I am willing to wait 1.5 secs for data to arive | |
% I wanted to make my buffer only big enough to store one message | |
set(xbee, 'InputBufferSize', 390 ) | |
% Before you can write to your serial port, you need to open it: | |
fopen(xbee); | |
disp('Serial port opened'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fprintf(xbee,'T'); | |
disp('Sent: T'); | |
pause(1); | |
ack = fscanf( xbee, '%s'); | |
if (strcmp(deblank(ack), 'Ok') == 1) | |
disp ('Received: OK'); | |
end | |
fprintf(xbee,'M'); | |
disp ('Sent: M'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fclose(xbee); | |
delete(xbee); | |
clear xbee |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Arduino Matlab communication | |
clear all; | |
clc; | |
delete(instrfindall); | |
%% Check serial objects & Connect to Port | |
% Check the port you are using with the arduino, then run: sudo ln -s /dev/ttyNUMBER /dev/ttyS101 | |
disp('Linux User? Have you run the simbolic link with ttyS101?'); | |
disp('sudo ln -s /dev/tty_NUMBER_ /dev/ttyS101'); | |
port = '/dev/ttyS101'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Ask desired Sample Rate in Hz | |
rate=input('Enter the samplerate in Hz. Max 500Hz: '); | |
delay = 1/rate; | |
str = sprintf('SampleRate fixed to: %f.', delay); | |
disp(str); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Initializinig rolling plot | |
buf_len = 100; | |
index = 1:buf_len; | |
% create variables for the Xaxis | |
gxdata = zeros(buf_len,1); | |
gydata = zeros(buf_len,1); | |
gzdata = zeros(buf_len,1); |
OlderNewer