mirror of
https://github.com/digistump/DigistumpArduino.git
synced 2026-02-10 08:55:07 -08:00
switch to setup for Arduino Boards Manager
This commit is contained in:
1216
digistump-sam/libraries/DigiFi/DigiFi.cpp
Normal file
1216
digistump-sam/libraries/DigiFi/DigiFi.cpp
Normal file
File diff suppressed because it is too large
Load Diff
162
digistump-sam/libraries/DigiFi/DigiFi.h
Normal file
162
digistump-sam/libraries/DigiFi/DigiFi.h
Normal file
@@ -0,0 +1,162 @@
|
||||
// DigiX WiFi module example - released by Digistump LLC/Erik Kettenburg under CC-BY-SA 3.0
|
||||
|
||||
|
||||
#ifndef DigiFi_h
|
||||
#define DigiFi_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#include <string.h>
|
||||
#include "Client.h"
|
||||
#include "IPAddress.h"
|
||||
|
||||
#define DIGIFI_RTS 105
|
||||
#define DIGIFI_CTS 104
|
||||
#define TCP 1
|
||||
#define UDP 0
|
||||
|
||||
class DigiFi : public Client
|
||||
{
|
||||
public:
|
||||
static const int requestTimeout = 15;
|
||||
String serverRequestPathString;
|
||||
DigiFi();
|
||||
|
||||
void begin(int aBaud = 9600, bool en = false);
|
||||
bool ready();
|
||||
void setDebug(bool debugStateVar);
|
||||
void setTCPTimeout(uint16_t timeout);
|
||||
bool serverRequest();
|
||||
void serverResponse(String response, int code = 200);
|
||||
String server(uint16_t port);
|
||||
String serverRequestPath();
|
||||
virtual int connect(IPAddress ip, uint16_t port);
|
||||
virtual int connect(const char *host, uint16_t port);
|
||||
virtual int disconnect();
|
||||
int get(char *aHost, char *aPath);
|
||||
int post(char *aHost, char *aPath, String postData);
|
||||
void startATMode();
|
||||
void endATMode();
|
||||
void close();
|
||||
void closeChunk();
|
||||
void printChunk(const char *str);
|
||||
void printChunk(int str);
|
||||
void printChunk(long str);
|
||||
void printChunk(String str);
|
||||
void setMode(uint8_t protocol = TCP);
|
||||
String header();
|
||||
String body();
|
||||
int lastError();
|
||||
void debug(String output);
|
||||
void debugWrite(char output);
|
||||
String URLEncode(String smsg);
|
||||
void setFlowControl(boolean);
|
||||
|
||||
//Ethernet implimentation
|
||||
IPAddress localIP();
|
||||
IPAddress subnetMask();
|
||||
IPAddress gatewayIP();
|
||||
IPAddress dnsServerIP();
|
||||
uint8_t maintain();
|
||||
|
||||
/* Client Implementation */
|
||||
virtual uint8_t connected();
|
||||
//uint8_t status();
|
||||
virtual operator bool();
|
||||
|
||||
virtual int available( void ) ;
|
||||
virtual int peek( void ) ;
|
||||
virtual int read( void ) ;
|
||||
virtual int read(uint8_t *buf, size_t size);
|
||||
virtual void flush( void ) ;
|
||||
virtual void stop( void ) ;
|
||||
virtual size_t write( const uint8_t c ) ;
|
||||
virtual size_t write(const uint8_t *buf, size_t size);
|
||||
using Print::write ; // pull in write(str) and write(buf, size) from Print
|
||||
|
||||
/* AT Wrappers */
|
||||
String AT(char *cmd, char *params);
|
||||
void toggleEcho(); //E
|
||||
String getWifiMode(); //WMODE AP STA APSTA
|
||||
void setWifiMode(char *mode);
|
||||
void setTransparent(); //ENTM
|
||||
String getTMode(); //TMODE throughput cmd
|
||||
void setTMode(char *mode);
|
||||
String getModId(); //MID
|
||||
String version(); //VER
|
||||
void factoryRestore(); //RELD rebooting...
|
||||
void reset(); //Z (No return)
|
||||
String help();//H
|
||||
int readConfig(byte* buffer);//CFGRD
|
||||
void writeConfig(byte* config, int len);//CFGWR
|
||||
int readFactoryDef(byte* buffer);//CFGFR
|
||||
void makeFactory(); //CFGTF
|
||||
String getUart();//UART baudrate,data_bits,stop_bit,parity
|
||||
void setUart(int baudrate,int data_bits,int stop_bit,char *parity);
|
||||
/* These are commented out as I'm unsure how they should be named
|
||||
String getAutoFrame(); //UARTF
|
||||
void setAutoFrame(char *para);
|
||||
int getAutoFrmTrigTime(); //UARTFT
|
||||
void setAutoFrmTrigTime(int ms);
|
||||
int getAutoFrmTrigLength(); //UARTFL
|
||||
void setAutoFrmTrigLength(int v);
|
||||
*/
|
||||
void sendData(int len, char *data);//SEND
|
||||
String recvData(int len);//RECV len,data (+ok=0 if timeout (3sec))
|
||||
String ping(char *ip);//PING Success Timeout Unknown host
|
||||
String getNetParams();//NETP (TCP|UDP),(SERVER|CLIENT),port,IP
|
||||
void setNetParams(char *proto, char *cs, int port, const char *ip);
|
||||
String getTCPLnk();//TCPLK on|off
|
||||
String getTCPTimeout();//TCPTO 0 <= int <= 600 (Def 300)
|
||||
String getTCPConn();//TCPDIS On|off
|
||||
void setTCPConn(char *sta);
|
||||
String getWSSSID();//WSSSID
|
||||
void setWSSSID(char *ssid);
|
||||
String getSTAKey();//WSKEY (OPEN|SHARED|WPAPSK|WPA2PSK),(NONE|WEP|TKIP|AES),key
|
||||
void setSTAKey(char* auth,char *encry,char *key);
|
||||
String getSTANetwork();//WANN (static|DHCP),ip,subnet,gateway
|
||||
void setSTANetwork(char *mode, char *ip, char *subnet, char *gateway);
|
||||
String getSTAMac();//WSMAC returns MAC
|
||||
void setSTAMac(int code, char *mac);//Code default is 8888, no idea what its for
|
||||
String STALinkStatus();//WSLK (Disconnected|AP SSID (AP MAC)|RF Off)
|
||||
String STASignalStrength();//WSLQ (Disconnected|Value)
|
||||
String scan();//WSCAN returns list
|
||||
String getSTADNS();//WSDNS address
|
||||
void setSTADNS(char *dns);
|
||||
String getAPNetwork();//LANN ip,subnet
|
||||
void setAPNetwork(char *ip, char *subnet);
|
||||
String getAPParams();//WAP (11B|11BG|11BGN),SSID,(AUTO|C1...C11)
|
||||
void setAPParams(char *mode, char *ssid, char *channel);
|
||||
String getAPKey();//WAKEY (OPEN|WPA2PSK),(NONE|AES),key
|
||||
void setAPKey(char* auth,char *encry,char *key);
|
||||
String getAPMac();//WAMAC returns MAC
|
||||
String getAPDHCP();//WADHCP (on|off)
|
||||
void setAPDHCP(char *status);
|
||||
String getAPPageDomain();//WADMN domain
|
||||
void setAPPageDomain(char *domain);
|
||||
void setPageDisplayMode(char *mode);//WEBSWITCH (iw|ew)
|
||||
void setPageLanguage(char *lang);//PLANG CN|EN
|
||||
String getUpgradeUrl();//UPURL url !!!DANGEROUS!!!
|
||||
void setUpgradeUrl(char *url);//url,filename (filename is optional, if provided upgrade is auto started)
|
||||
String getUpgradeFile();//UPFILE filename !!!DANGEROUS!!!
|
||||
void setUpgradeFile(char *filename);
|
||||
String startUpgrade();//UPST !!!DANGEROUS!!!
|
||||
String getWebAuth();//WEBU user,pass
|
||||
void setWebAuth(char *user, char *pass);
|
||||
String getSleepMode();//MSLP normal|standby
|
||||
void setSleepMode(char *mode);
|
||||
void setModId(char *modid);//WRMID
|
||||
String getWifiCfgPassword();//ASWD aswd
|
||||
void setWifiCfgPassword(char *aswd);
|
||||
private:
|
||||
String readResponse(int contentLength);
|
||||
bool startATSequence();
|
||||
String aHeader;
|
||||
String aBody;
|
||||
//String lastHost;
|
||||
int lastErr;
|
||||
bool debugState;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
4
digistump-sam/libraries/DigiFi/README.md
Normal file
4
digistump-sam/libraries/DigiFi/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
DigiFi
|
||||
======
|
||||
|
||||
DigiX WiFi Library for the WIFI232-G Module
|
||||
@@ -0,0 +1,61 @@
|
||||
// DigiX WiFi module example - released by Digistump LLC/Erik Kettenburg under CC-BY-SA 3.0
|
||||
// Inspired by HttpClient library by MCQN Ltd.
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
DigiFi wifi;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize serial communications at 9600 bps:
|
||||
Serial.begin(9600);
|
||||
wifi.begin(9600);
|
||||
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Serial.println("Starting");
|
||||
|
||||
while (wifi.ready() != 1)
|
||||
{
|
||||
Serial.println("Error connecting to network");
|
||||
delay(15000);
|
||||
}
|
||||
|
||||
Serial.println("Connected to wifi!");
|
||||
|
||||
//GET request example
|
||||
|
||||
if(wifi.get("digistump.com","/test.txt")){
|
||||
String body = wifi.body();
|
||||
Serial.println(body);
|
||||
}
|
||||
else{
|
||||
Serial.println("error");
|
||||
|
||||
}
|
||||
|
||||
//POST request example
|
||||
Serial.println("Sending tweet!");
|
||||
//To use thingspeak for sending tweets see: http://community.thingspeak.com/documentation/apps/thingtweet/
|
||||
if(wifi.post("api.thingspeak.com","/apps/thingtweet/1/statuses/update","api_key=[YOURTHINGTWEETAPIKEY]&status="+wifi.URLEncode("Tweet from my new DigiX! #digix #digistump http://digistump.com"))){
|
||||
String body = wifi.body();
|
||||
Serial.println(body);
|
||||
}
|
||||
else{
|
||||
Serial.println("error");
|
||||
|
||||
}
|
||||
|
||||
|
||||
wifi.close();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Chat Server
|
||||
|
||||
A simple server that distributes any incoming messages to all
|
||||
connected clients. To use telnet to your device's IP address and type.
|
||||
You can see the client's input in the serial monitor as well.
|
||||
Using a DigiX.
|
||||
|
||||
Circuit:
|
||||
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
modified Dec 22, 2013 for use with DigiX by Erik Kettenburg
|
||||
|
||||
*/
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
|
||||
DigiFi server;
|
||||
boolean alreadyConnected = false; // whether or not the client was connected previously
|
||||
|
||||
void setup() {
|
||||
|
||||
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// start listening for clients
|
||||
server.begin();
|
||||
server.server(8080); //connect to it on port 8080
|
||||
|
||||
while (server.ready() != 1)
|
||||
{
|
||||
Serial.println("Connecting to network...");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Serial.print("Chat server address:");
|
||||
Serial.println(server.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// wait for a new client:
|
||||
|
||||
// when the client sends the first byte, say hello:
|
||||
if (server.available() > 0) {
|
||||
if (!alreadyConnected) {
|
||||
// clead out the input buffer:
|
||||
server.flush();
|
||||
Serial.println("We have a new client");
|
||||
server.println("Hello, client!");
|
||||
alreadyConnected = true;
|
||||
}
|
||||
|
||||
|
||||
// read the bytes incoming from the client:
|
||||
char thisChar = server.read();
|
||||
// echo the bytes back to the client:
|
||||
server.write(thisChar);
|
||||
// echo the bytes to the server as well:
|
||||
Serial.write(thisChar);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
Telnet client
|
||||
|
||||
This sketch connects to a a telnet server (http://www.google.com)
|
||||
using a DigiX. You'll need a telnet server
|
||||
to test this with.
|
||||
Processing's ChatServer example (part of the network library) works well,
|
||||
running on port 10002. It can be found as part of the examples
|
||||
in the Processing application, available at
|
||||
http://processing.org/
|
||||
|
||||
|
||||
created 14 Sep 2010
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
modified Dec 22, 2013 for use with DigiX by Erik Kettenburg
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
|
||||
// Enter the IP address of the server you're connecting to:
|
||||
IPAddress server(1, 1, 1, 1);
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 23 is default for telnet;
|
||||
// if you're using Processing's ChatServer, use port 10002):
|
||||
DigiFi client;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Serial.println("Connecting...");
|
||||
// start the connection:
|
||||
client.begin(9600);
|
||||
client.connect(server,23);
|
||||
Serial.println("Connected.");
|
||||
//client.setDebug(true);
|
||||
//wait for module to be ready
|
||||
while (client.ready() != 1)
|
||||
{
|
||||
Serial.println("Connecting to network...");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
||||
// as long as there are bytes in the serial queue,
|
||||
// read them and send them out the socket if it's open:
|
||||
while (Serial.available() > 0) {
|
||||
char inChar = Serial.read();
|
||||
if (client.connected()) {
|
||||
client.print(inChar);
|
||||
}
|
||||
}
|
||||
|
||||
// if the server's disconnected, stop the client:
|
||||
if (!client.connected()) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
// do nothing:
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
|
||||
Udp NTP Client
|
||||
|
||||
Get the time from a Network Time Protocol (NTP) time server
|
||||
Demonstrates use of UDP sendPacket and ReceivePacket
|
||||
For more on NTP time servers and the messages needed to communicate with them,
|
||||
see http://en.wikipedia.org/wiki/Network_Time_Protocol
|
||||
|
||||
created 4 Sep 2010
|
||||
by Michael Margolis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
modified Dec 22, 2013 for use with DigiX by Erik Kettenburg
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server
|
||||
|
||||
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
|
||||
|
||||
uint8_t packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
||||
|
||||
DigiFi client;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// start the connection:
|
||||
client.begin(9600);
|
||||
//client.setDebug(true);
|
||||
//wait for module to be ready
|
||||
while (client.ready() != 1)
|
||||
{
|
||||
Serial.println("Connecting to network...");
|
||||
delay(1000);
|
||||
}
|
||||
client.setMode(UDP); //must come before connect
|
||||
Serial.println("Setting up UDP connection");
|
||||
client.connect(timeServer,123);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
sendNTPpacket(); // send an NTP packet to a time server
|
||||
|
||||
// wait to see if a reply is available
|
||||
delay(1000);
|
||||
if ( client.available() ) {
|
||||
// We've received a packet, read the data from it
|
||||
client.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
|
||||
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
||||
// or two words, long. First, esxtract the two words:
|
||||
|
||||
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
||||
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
||||
// combine the four bytes (two words) into a long integer
|
||||
// this is NTP time (seconds since Jan 1 1900):
|
||||
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
||||
Serial.print("Seconds since Jan 1 1900 = " );
|
||||
Serial.println(secsSince1900);
|
||||
|
||||
// now convert NTP time into everyday time:
|
||||
Serial.print("Unix time = ");
|
||||
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
|
||||
const unsigned long seventyYears = 2208988800UL;
|
||||
// subtract seventy years:
|
||||
unsigned long epoch = secsSince1900 - seventyYears;
|
||||
// print Unix time:
|
||||
Serial.println(epoch);
|
||||
|
||||
|
||||
// print the hour, minute and second:
|
||||
Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
|
||||
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
|
||||
Serial.print(':');
|
||||
if ( ((epoch % 3600) / 60) < 10 ) {
|
||||
// In the first 10 minutes of each hour, we'll want a leading '0'
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
|
||||
Serial.print(':');
|
||||
if ( (epoch % 60) < 10 ) {
|
||||
// In the first 10 seconds of each minute, we'll want a leading '0'
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.println(epoch % 60); // print the second
|
||||
}
|
||||
// wait ten seconds before asking for the time again
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// send an NTP request to the time server at the given address
|
||||
unsigned long sendNTPpacket()
|
||||
{
|
||||
// set all bytes in the buffer to 0
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
// Initialize values needed to form NTP request
|
||||
// (see URL above for details on the packets)
|
||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
packetBuffer[1] = 0; // Stratum, or type of clock
|
||||
packetBuffer[2] = 6; // Polling Interval
|
||||
packetBuffer[3] = 0xEC; // Peer Clock Precision
|
||||
// 8 bytes of zero for Root Delay & Root Dispersion
|
||||
packetBuffer[12] = 49;
|
||||
packetBuffer[13] = 0x4E;
|
||||
packetBuffer[14] = 49;
|
||||
packetBuffer[15] = 52;
|
||||
|
||||
// all NTP fields have been given values, now
|
||||
// you can send a packet requesting a timestamp:
|
||||
client.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Web client
|
||||
|
||||
This sketch connects to a website (http://www.google.com)
|
||||
using an DigiX.
|
||||
|
||||
Based on example by David A. Mellis, Tom Igoe, and Adrian McEwen
|
||||
|
||||
*/
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
|
||||
// if you don't want to use DNS - though it is handeled by the WiFI module
|
||||
//so there is no size penalty for using it -
|
||||
// use the numeric IP instead of the name for the server:
|
||||
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
|
||||
char server[] = "digistump.com"; // name address for Google (using DNS)
|
||||
|
||||
// Initialize the Wifi library (client/server/and main all in one)
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 80 is default for HTTP):
|
||||
DigiFi client;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// start the connection:
|
||||
client.begin(9600);
|
||||
//client.setDebug(true);
|
||||
//wait for module to be ready
|
||||
while (client.ready() != 1)
|
||||
{
|
||||
Serial.println("Connecting to network...");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
Serial.println("connecting...");
|
||||
|
||||
// if you get a connection, report back via serial:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connected");
|
||||
// Make a HTTP request:
|
||||
client.println("GET /test.txt HTTP/1.1");
|
||||
client.println("Host: www.digistump.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
}
|
||||
else {
|
||||
// kf you didn't get a connection to the server:
|
||||
Serial.println("connection failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
//while(!Serial1.available()){}
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
||||
// if the server's disconnected, stop the client:
|
||||
if (!client.connected()) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Web Server
|
||||
|
||||
A simple web server that shows the value of the analog input pins.
|
||||
Using a DigiX.
|
||||
|
||||
Circuit:
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
modified Dec 22, 2013 for use with DigiX by Erik Kettenburg
|
||||
|
||||
*/
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
// Initialize the DigiFi library
|
||||
// with the IP address and port you want to use
|
||||
// (port 80 is default for HTTP):
|
||||
DigiFi server;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// start the server:
|
||||
server.begin();
|
||||
server.server(8080); //start server on port 8080
|
||||
server.setTCPTimeout(1); //force wifi to close connection after idle for 1 second
|
||||
//fix for not being able to close client connections
|
||||
//see WebServerChunked for a better approach
|
||||
while (server.ready() != 1)
|
||||
{
|
||||
Serial.println("Connecting to network...");
|
||||
delay(1000);
|
||||
}
|
||||
Serial.print("server is at ");
|
||||
Serial.println(server.localIP());
|
||||
}
|
||||
|
||||
boolean currentLineIsBlank = false;
|
||||
void loop() {
|
||||
// listen for incoming
|
||||
// an http request ends with a blank line
|
||||
|
||||
|
||||
if (server.available()) {
|
||||
char c = server.read();
|
||||
Serial.write(c);
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so you can send a reply
|
||||
if (c == '\n' && currentLineIsBlank) {
|
||||
// send a standard http response header
|
||||
server.println("HTTP/1.1 200 OK");
|
||||
server.println("Content-Type: text/html");
|
||||
server.println("Connection: close"); // the connection will be closed after completion of the response
|
||||
server.println("Refresh: 5"); // refresh the page automatically every 5 sec
|
||||
server.println();
|
||||
server.println("<!DOCTYPE HTML>");
|
||||
server.println("<html>");
|
||||
// output the value of each analog input pin
|
||||
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
|
||||
int sensorReading = analogRead(analogChannel);
|
||||
server.print("analog input ");
|
||||
server.print(analogChannel);
|
||||
server.print(" is ");
|
||||
server.print(sensorReading);
|
||||
server.println("<br />");
|
||||
}
|
||||
server.println("</html>");
|
||||
server.println("");
|
||||
server.println("");
|
||||
currentLineIsBlank = false;
|
||||
|
||||
}
|
||||
else if (c == '\n') {
|
||||
// you're starting a new line
|
||||
currentLineIsBlank = true;
|
||||
}
|
||||
else if (c != '\r') {
|
||||
// you've gotten a character on the current line
|
||||
currentLineIsBlank = false;
|
||||
}
|
||||
}
|
||||
|
||||
// give the web browser time to receive the data
|
||||
delay(1);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Web Server
|
||||
|
||||
A simple web server that shows the value of the analog input pins.
|
||||
Using a DigiX.
|
||||
|
||||
Circuit:
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
modified Dec 22, 2013 for use with DigiX by Erik Kettenburg
|
||||
|
||||
*/
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
// Initialize the DigiFi library
|
||||
// with the IP address and port you want to use
|
||||
// (port 80 is default for HTTP):
|
||||
DigiFi server;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// start the server:
|
||||
server.begin();
|
||||
server.server(8080); //start server on port 8080
|
||||
while (server.ready() != 1)
|
||||
{
|
||||
Serial.println("Connecting to network...");
|
||||
delay(1000);
|
||||
}
|
||||
Serial.print("server is at ");
|
||||
Serial.println(server.localIP());
|
||||
}
|
||||
|
||||
boolean currentLineIsBlank = false;
|
||||
void loop() {
|
||||
// listen for incoming
|
||||
// an http request ends with a blank line
|
||||
|
||||
|
||||
if (server.available()) {
|
||||
char c = server.read();
|
||||
Serial.write(c);
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so you can send a reply
|
||||
if (c == '\n' && currentLineIsBlank) {
|
||||
// send a standard http response header
|
||||
server.println("HTTP/1.1 200 OK");
|
||||
server.println("Content-Type: text/html");
|
||||
server.println("Connection: close"); // the connection will be closed after completion of the response
|
||||
//server.println("Refresh: 5"); // refresh the page automatically every 5 sec
|
||||
server.println("Transfer-Encoding: chunked");
|
||||
server.println();
|
||||
server.printChunk("<!DOCTYPE HTML>");
|
||||
server.printChunk("<html>");
|
||||
// output the value of each analog input pin
|
||||
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
|
||||
int sensorReading = analogRead(analogChannel);
|
||||
server.printChunk("analog input ");
|
||||
server.printChunk(analogChannel);
|
||||
server.printChunk(" is ");
|
||||
server.printChunk(sensorReading);
|
||||
server.printChunk("<br />");
|
||||
}
|
||||
server.printChunk("</html>");
|
||||
server.closeChunk();
|
||||
|
||||
currentLineIsBlank = false;
|
||||
|
||||
}
|
||||
else if (c == '\n') {
|
||||
// you're starting a new line
|
||||
currentLineIsBlank = true;
|
||||
}
|
||||
else if (c != '\r') {
|
||||
// you've gotten a character on the current line
|
||||
currentLineIsBlank = false;
|
||||
}
|
||||
}
|
||||
|
||||
// give the web browser time to receive the data
|
||||
delay(1);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
bool start = true;
|
||||
String message = "";
|
||||
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
DigiFi wifi;
|
||||
|
||||
//#define DEBUG
|
||||
#include <Wire.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
|
||||
#include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85
|
||||
|
||||
#define GPIO_ADDR 0x27 // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A - 0x27 is the address of the Digispark LCD modules.
|
||||
|
||||
|
||||
LiquidCrystal_I2C lcd(GPIO_ADDR,16,2); // set address & 16 chars / 2 lines
|
||||
|
||||
|
||||
|
||||
// Require keyboard control library
|
||||
#include <KeyboardController.h>
|
||||
|
||||
// Initialize USB Controller
|
||||
USBHost usb;
|
||||
|
||||
// Attach keyboard controller to USB
|
||||
KeyboardController keyboard(usb);
|
||||
|
||||
// This function intercepts key press
|
||||
void keyPressed() {
|
||||
|
||||
}
|
||||
|
||||
// This function intercepts key release
|
||||
void keyReleased() {
|
||||
|
||||
printKey();
|
||||
}
|
||||
|
||||
void printKey() {
|
||||
|
||||
if(start){
|
||||
lcd.clear();
|
||||
lcd.home();
|
||||
start = false;
|
||||
}
|
||||
|
||||
if(keyboard.getOemKey()==40){//enter pressed
|
||||
lcd.noAutoscroll();
|
||||
lcd.clear();
|
||||
lcd.home();
|
||||
lcd.print("Sending tweet...");
|
||||
if(wifi.post("api.thingspeak.com","/apps/thingtweet/1/statuses/update","api_key=[YOURTHINGTWEETAPIKEY]&status="+wifi.URLEncode(message))){
|
||||
lcd.clear();
|
||||
lcd.home();
|
||||
lcd.print("Tweet sent!");
|
||||
}
|
||||
else{
|
||||
lcd.clear();
|
||||
lcd.home();
|
||||
lcd.print("Error sending!");
|
||||
}
|
||||
delay(3000);
|
||||
lcd.clear();
|
||||
lcd.home();
|
||||
lcd.print("DigiX - Ready!");
|
||||
message ="";
|
||||
start=true;
|
||||
lcd.noAutoscroll();
|
||||
}
|
||||
else{
|
||||
// getKey() returns the ASCII translation of OEM key
|
||||
// combined with modifiers.
|
||||
|
||||
char nextChar = keyboard.getKey();
|
||||
lcd.print(nextChar);
|
||||
message += nextChar;
|
||||
if(message.length()==16)
|
||||
lcd.autoscroll();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire1.begin(); // initialize I2C lib - comment this out to use with standard arduinos
|
||||
lcd.init(); // initialize the lcd
|
||||
lcd.backlight(); // Print a message to the LCD.
|
||||
lcd.print("Starting....");
|
||||
delay(5000); //give wifi some time to warm up
|
||||
lcd.clear();
|
||||
lcd.print("WiFi Starting...");
|
||||
wifi.begin(9600);
|
||||
|
||||
delay(200);
|
||||
|
||||
while (wifi.ready() != 1)
|
||||
{
|
||||
lcd.home();
|
||||
lcd.print("WiFi not ready");
|
||||
delay(15000);
|
||||
}
|
||||
lcd.clear();
|
||||
lcd.home();
|
||||
lcd.print("DigiX - Ready!");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Process USB tasks
|
||||
usb.Task();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <DigiFi.h>
|
||||
DigiFi wifi;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
wifi.begin(9600);
|
||||
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Serial.println("Starting");
|
||||
|
||||
while (wifi.ready() != 1)
|
||||
{
|
||||
Serial.println("Error connecting to network");
|
||||
delay(15000);
|
||||
}
|
||||
|
||||
Serial.println("Connected to wifi!");
|
||||
Serial.print("Server running at: ");
|
||||
String address = wifi.server(8080);//sets up server and returns IP
|
||||
Serial.println(address);
|
||||
|
||||
// wifi.close();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if ( wifi.serverRequest()){
|
||||
Serial.print("Request for: ");
|
||||
Serial.println(wifi.serverRequestPath());
|
||||
if(wifi.serverRequestPath()!="/")
|
||||
wifi.serverResponse("404 Not Found",404);
|
||||
else
|
||||
wifi.serverResponse("<html><body><h1>This is a test</h1></body></html>"); //defaults to 200
|
||||
}
|
||||
|
||||
delay(10);
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
|
||||
Udp NTP Client
|
||||
|
||||
Uses both Due_RTC library and DigiFi to connect to NTP server
|
||||
get current time and set RTC to that time.
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
*/
|
||||
#include <rtc_clock.h>
|
||||
#include <DigiFi.h>
|
||||
|
||||
RTC_clock rtc_clock(XTAL);
|
||||
|
||||
char* daynames[]={"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
|
||||
int hh,mm,ss,dow,dd,mon,yyyy;
|
||||
|
||||
char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server
|
||||
|
||||
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
|
||||
|
||||
uint8_t packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
||||
|
||||
DigiFi client;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
rtc_clock.init();
|
||||
// start the connection:
|
||||
client.begin(9600);
|
||||
//client.setDebug(true);
|
||||
//wait for module to be ready
|
||||
while (client.ready() != 1)
|
||||
{
|
||||
Serial.println("Connecting to network...");
|
||||
delay(1000);
|
||||
}
|
||||
client.setMode(UDP); //must come before connect
|
||||
rtc_clock.set_time(__TIME__);
|
||||
Serial.println("Setting up UDP connection");
|
||||
client.connect(timeServer,123);
|
||||
unsigned long ntpUnixTime = 0;
|
||||
while(ntpUnixTime == 0){
|
||||
sendNTPpacket(); // send an NTP packet to a time server
|
||||
delay(1000);
|
||||
ntpUnixTime = getNTPpacket();
|
||||
}
|
||||
Serial.print("Got NTP Timestamp: ");
|
||||
Serial.println(ntpUnixTime);
|
||||
Serial.println("Setting RTC Clock");
|
||||
rtc_clock.set_timestamp(ntpUnixTime);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print("Time: ");
|
||||
rtc_clock.get_time(&hh,&mm,&ss);
|
||||
rtc_clock.get_date(&dow,&dd,&mon,&yyyy);
|
||||
digitprint(hh, 2);
|
||||
Serial.print(":");
|
||||
digitprint(mm, 2);
|
||||
Serial.print(":");
|
||||
digitprint(ss, 2);
|
||||
Serial.println("");
|
||||
Serial.print("Date: ");
|
||||
Serial.print(daynames[dow-1]);
|
||||
Serial.print(" ");
|
||||
digitprint(dd, 2);
|
||||
Serial.print(".");
|
||||
digitprint(mon, 2);
|
||||
Serial.print(".");
|
||||
Serial.println(yyyy);
|
||||
Serial.println("");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// send an NTP request to the time server at the given address
|
||||
unsigned long sendNTPpacket()
|
||||
{
|
||||
// set all bytes in the buffer to 0
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
// Initialize values needed to form NTP request
|
||||
// (see URL above for details on the packets)
|
||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
packetBuffer[1] = 0; // Stratum, or type of clock
|
||||
packetBuffer[2] = 6; // Polling Interval
|
||||
packetBuffer[3] = 0xEC; // Peer Clock Precision
|
||||
// 8 bytes of zero for Root Delay & Root Dispersion
|
||||
packetBuffer[12] = 49;
|
||||
packetBuffer[13] = 0x4E;
|
||||
packetBuffer[14] = 49;
|
||||
packetBuffer[15] = 52;
|
||||
|
||||
// all NTP fields have been given values, now
|
||||
// you can send a packet requesting a timestamp:
|
||||
client.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
|
||||
}
|
||||
|
||||
unsigned long getNTPpacket(){
|
||||
if ( client.available() ) {
|
||||
// We've received a packet, read the data from it
|
||||
client.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
|
||||
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
||||
// or two words, long. First, esxtract the two words:
|
||||
|
||||
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
||||
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
||||
// combine the four bytes (two words) into a long integer
|
||||
// this is NTP time (seconds since Jan 1 1900):
|
||||
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
||||
//Serial.print("Seconds since Jan 1 1900 = " );
|
||||
//Serial.println(secsSince1900);
|
||||
|
||||
// now convert NTP time into everyday time:
|
||||
//Serial.print("Unix time = ");
|
||||
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
|
||||
const unsigned long seventyYears = 2208988800UL;
|
||||
// subtract seventy years:
|
||||
unsigned long epoch = secsSince1900 - seventyYears;
|
||||
// print Unix time:
|
||||
return epoch;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void digitprint(int value, int lenght){
|
||||
for (int i = 0; i < (lenght - numdigits(value)); i++){
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(value);
|
||||
}
|
||||
|
||||
int numdigits(int i){
|
||||
int digits;
|
||||
if (i < 10)
|
||||
digits = 1;
|
||||
else
|
||||
digits = (int)(log10((double)i)) + 1;
|
||||
return digits;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
// ThingSpeak Settings
|
||||
char thingSpeakAddress[] = "api.thingspeak.com";
|
||||
String writeAPIKey = "XXXMX2WYYR0EV68M";
|
||||
const int updateThingSpeakInterval = 16 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)
|
||||
|
||||
// Variable Setup
|
||||
long lastConnectionTime = 0;
|
||||
int failedCounter = 0;
|
||||
|
||||
// Initialize DigiFi
|
||||
DigiFi client;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Start Serial for debugging on the Serial Monitor
|
||||
Serial.begin(9600);
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
// Start DigiFi
|
||||
startDigiFi();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Read value from Analog Input Pin 0
|
||||
String analogPin0 = String(analogRead(A0), DEC);
|
||||
|
||||
|
||||
// Update ThingSpeak
|
||||
if(millis() - lastConnectionTime > updateThingSpeakInterval)
|
||||
{
|
||||
updateThingSpeak("field1="+analogPin0);
|
||||
}
|
||||
|
||||
// Check if Arduino Ethernet needs to be restarted
|
||||
if (failedCounter > 3 ) {startDigiFi();}
|
||||
|
||||
}
|
||||
|
||||
void updateThingSpeak(String tsData)
|
||||
{
|
||||
if (client.connect(thingSpeakAddress, 80))
|
||||
{
|
||||
|
||||
lastConnectionTime = millis();
|
||||
if(wifi.post("api.thingspeak.com","/update","api_key="++writeAPIKey++"&status="+wifi.URLEncode(tsData)))
|
||||
{
|
||||
Serial.println("Sent to ThingSpeak");
|
||||
Serial.println();
|
||||
failedCounter = 0;
|
||||
Serial.println(wifi.body());
|
||||
}
|
||||
else
|
||||
{
|
||||
failedCounter++;
|
||||
|
||||
Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
failedCounter++;
|
||||
|
||||
Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
|
||||
Serial.println();
|
||||
|
||||
lastConnectionTime = millis();
|
||||
}
|
||||
}
|
||||
|
||||
void startDigiFi()
|
||||
{
|
||||
|
||||
|
||||
|
||||
Serial.println("Connecting Arduino to network...");
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
|
||||
// Connect to network amd obtain an IP address using DHCP
|
||||
client.begin();
|
||||
client.setDebug(true);
|
||||
while (client.ready() != 1)
|
||||
{
|
||||
Serial.println("Connecting to network...");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
61
digistump-sam/libraries/DigiFi/examples/basic/basic.ino
Normal file
61
digistump-sam/libraries/DigiFi/examples/basic/basic.ino
Normal file
@@ -0,0 +1,61 @@
|
||||
// DigiX WiFi module example - released by Digistump LLC/Erik Kettenburg under CC-BY-SA 3.0
|
||||
// Inspired by HttpClient library by MCQN Ltd.
|
||||
|
||||
#include <DigiFi.h>
|
||||
|
||||
DigiFi wifi;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize serial communications at 9600 bps:
|
||||
Serial.begin(9600);
|
||||
wifi.begin(9600);
|
||||
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Serial.println("Starting");
|
||||
|
||||
while (wifi.ready() != 1)
|
||||
{
|
||||
Serial.println("Error connecting to network");
|
||||
delay(15000);
|
||||
}
|
||||
|
||||
Serial.println("Connected to wifi!");
|
||||
|
||||
//GET request example
|
||||
|
||||
if(wifi.get("digistump.com","/test.txt")){
|
||||
String body = wifi.body();
|
||||
Serial.println(body);
|
||||
}
|
||||
else{
|
||||
Serial.println("error");
|
||||
|
||||
}
|
||||
|
||||
//POST request example
|
||||
Serial.println("Sending tweet!");
|
||||
//To use thingspeak for sending tweets see: http://community.thingspeak.com/documentation/apps/thingtweet/
|
||||
if(wifi.post("api.thingspeak.com","/apps/thingtweet/1/statuses/update","api_key=[YOURTHINGTWEETAPIKEY]&status="+wifi.URLEncode("Tweet from my new DigiX! #digix #digistump http://digistump.com"))){
|
||||
String body = wifi.body();
|
||||
Serial.println(body);
|
||||
}
|
||||
else{
|
||||
Serial.println("error");
|
||||
|
||||
}
|
||||
|
||||
|
||||
wifi.close();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
33
digistump-sam/libraries/DigiFi/examples/ping/ping.ino
Normal file
33
digistump-sam/libraries/DigiFi/examples/ping/ping.ino
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <DigiFi.h>
|
||||
DigiFi wifi;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
wifi.begin(9600);
|
||||
|
||||
//DigiX trick - since we are on serial over USB wait for character to be entered in serial terminal
|
||||
while(!Serial.available()){
|
||||
Serial.println("Enter any key to begin");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Serial.println("Starting");
|
||||
|
||||
while (wifi.ready() != 1)
|
||||
{
|
||||
Serial.println("Error connecting to network");
|
||||
delay(15000);
|
||||
}
|
||||
|
||||
Serial.println("Connected to wifi!");
|
||||
wifi.startATMode();
|
||||
Serial.println(wifi.ping("192.168.2.1"));
|
||||
wifi.endATMode();
|
||||
wifi.close();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/* Software Debouncing - Mechanical Rotary Encoder */
|
||||
|
||||
#define encoder0PinA 9
|
||||
#define encoder0PinB 10
|
||||
const int buttonPin = 12;
|
||||
volatile unsigned int encoder0Pos = 0;
|
||||
static boolean rotating=false;
|
||||
int buttonState; // the current reading from the input pin
|
||||
int lastButtonState = LOW; // the previous reading from the input pin
|
||||
long lastDebounceTime = 0; // the last time the output pin was toggled
|
||||
long debounceDelay = 50; // the debounce time; increase if the output flickers
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT);
|
||||
digitalWrite(buttonPin, HIGH);
|
||||
pinMode(encoder0PinA, INPUT);
|
||||
digitalWrite(encoder0PinA, HIGH);
|
||||
pinMode(encoder0PinB, INPUT);
|
||||
digitalWrite(encoder0PinB, HIGH);
|
||||
|
||||
attachInterrupt(encoder0PinA, rotEncoder, CHANGE);
|
||||
SerialUSB.begin (9600);
|
||||
}
|
||||
|
||||
void rotEncoder(){
|
||||
rotating=true;
|
||||
// If a signal change (noise or otherwise) is detected
|
||||
// in the rotary encoder, the flag is set to true
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while(rotating) {
|
||||
delay(2);
|
||||
// When signal changes we wait 2 milliseconds for it to
|
||||
// stabilise before reading (increase this value if there
|
||||
// still bounce issues)
|
||||
if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
|
||||
encoder0Pos++;
|
||||
}
|
||||
else {
|
||||
encoder0Pos--;
|
||||
}
|
||||
rotating=false; // Reset the flag back to false
|
||||
SerialUSB.println(encoder0Pos);
|
||||
}
|
||||
int reading = digitalRead(buttonPin);
|
||||
|
||||
// check to see if you just pressed the button
|
||||
// (i.e. the input went from LOW to HIGH), and you've waited
|
||||
// long enough since the last press to ignore any noise:
|
||||
|
||||
// If the switch changed, due to noise or pressing:
|
||||
if (reading != lastButtonState) {
|
||||
// reset the debouncing timer
|
||||
lastDebounceTime = millis();
|
||||
SerialUSB.print("Button: ");
|
||||
SerialUSB.println(reading);
|
||||
}
|
||||
|
||||
if ((millis() - lastDebounceTime) > debounceDelay) {
|
||||
// whatever the reading is at, it's been there for longer
|
||||
// than the debounce delay, so take it as the actual current state:
|
||||
buttonState = reading;
|
||||
}
|
||||
|
||||
|
||||
// save the reading. Next time through the loop,
|
||||
// it'll be the lastButtonState:
|
||||
lastButtonState = reading;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
int irPin=11;
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(irPin,INPUT);
|
||||
pinMode(13,OUTPUT);
|
||||
Serial.begin(9600);
|
||||
digitalWrite(13,HIGH);
|
||||
Serial.println("You pressed a button");
|
||||
delay(1000);
|
||||
digitalWrite(13,LOW);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if(pulseIn(irPin,LOW))
|
||||
{
|
||||
//button pressed
|
||||
delay(100);
|
||||
digitalWrite(13,HIGH);
|
||||
Serial.println("You pressed a button");
|
||||
delay(1000);
|
||||
digitalWrite(13,LOW);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
int RedPin = 5;
|
||||
int GreenPin = 6;
|
||||
int BluePin = 7;
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
pinMode(RedPin, OUTPUT);
|
||||
pinMode(GreenPin, OUTPUT);
|
||||
pinMode(BluePin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
randomSeed(analogRead(0));
|
||||
// put your main code here, to run repeatedly:
|
||||
analogWrite(RedPin,random(255));
|
||||
analogWrite(GreenPin,random(255));
|
||||
analogWrite(BluePin,random(255));
|
||||
|
||||
delay(500);
|
||||
}
|
||||
112
digistump-sam/libraries/DigiXBetaBonus/Bonus_Temp/Bonus_Temp.ino
Normal file
112
digistump-sam/libraries/DigiXBetaBonus/Bonus_Temp/Bonus_Temp.ino
Normal file
@@ -0,0 +1,112 @@
|
||||
#include <OneWire.h>
|
||||
//DigiX Bonus Shield Temp example - modfied by Erik Kettenburg, Digistump LLC from:
|
||||
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
|
||||
//
|
||||
// http://www.pjrc.com/teensy/td_libs_OneWire.html
|
||||
//
|
||||
// The DallasTemperature library can do all this work for you!
|
||||
// http://milesburton.com/Dallas_Temperature_Control_Library
|
||||
|
||||
OneWire ds(8); // on pin 10 (a 4.7K resistor is necessary)
|
||||
|
||||
void setup(void) {
|
||||
SerialUSB.begin(9600);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
byte i;
|
||||
byte present = 0;
|
||||
byte type_s;
|
||||
byte data[12];
|
||||
byte addr[8];
|
||||
float celsius, fahrenheit;
|
||||
|
||||
if ( !ds.search(addr)) {
|
||||
SerialUSB.println("No more addresses.");
|
||||
SerialUSB.println();
|
||||
ds.reset_search();
|
||||
delay(250);
|
||||
return;
|
||||
}
|
||||
|
||||
SerialUSB.print("ROM =");
|
||||
for( i = 0; i < 8; i++) {
|
||||
SerialUSB.write(' ');
|
||||
SerialUSB.print(addr[i], HEX);
|
||||
}
|
||||
|
||||
if (OneWire::crc8(addr, 7) != addr[7]) {
|
||||
SerialUSB.println("CRC is not valid!");
|
||||
return;
|
||||
}
|
||||
SerialUSB.println();
|
||||
|
||||
// the first ROM byte indicates which chip
|
||||
switch (addr[0]) {
|
||||
case 0x10:
|
||||
SerialUSB.println(" Chip = DS18S20"); // or old DS1820
|
||||
type_s = 1;
|
||||
break;
|
||||
case 0x28:
|
||||
SerialUSB.println(" Chip = DS18B20");
|
||||
type_s = 0;
|
||||
break;
|
||||
case 0x22:
|
||||
SerialUSB.println(" Chip = DS1822");
|
||||
type_s = 0;
|
||||
break;
|
||||
default:
|
||||
SerialUSB.println("Device is not a DS18x20 family device.");
|
||||
return;
|
||||
}
|
||||
|
||||
ds.reset();
|
||||
ds.select(addr);
|
||||
ds.write(0x44, 1); // start conversion, with parasite power on at the end
|
||||
|
||||
delay(1000); // maybe 750ms is enough, maybe not
|
||||
// we might do a ds.depower() here, but the reset will take care of it.
|
||||
|
||||
present = ds.reset();
|
||||
ds.select(addr);
|
||||
ds.write(0xBE); // Read Scratchpad
|
||||
|
||||
SerialUSB.print(" Data = ");
|
||||
SerialUSB.print(present, HEX);
|
||||
SerialUSB.print(" ");
|
||||
for ( i = 0; i < 9; i++) { // we need 9 bytes
|
||||
data[i] = ds.read();
|
||||
SerialUSB.print(data[i], HEX);
|
||||
SerialUSB.print(" ");
|
||||
}
|
||||
SerialUSB.print(" CRC=");
|
||||
SerialUSB.print(OneWire::crc8(data, 8), HEX);
|
||||
SerialUSB.println();
|
||||
|
||||
// Convert the data to actual temperature
|
||||
// because the result is a 16 bit signed integer, it should
|
||||
// be stored to an "int16_t" type, which is always 16 bits
|
||||
// even when compiled on a 32 bit processor.
|
||||
int16_t raw = (data[1] << 8) | data[0];
|
||||
if (type_s) {
|
||||
raw = raw << 3; // 9 bit resolution default
|
||||
if (data[7] == 0x10) {
|
||||
// "count remain" gives full 12 bit resolution
|
||||
raw = (raw & 0xFFF0) + 12 - data[6];
|
||||
}
|
||||
} else {
|
||||
byte cfg = (data[4] & 0x60);
|
||||
// at lower res, the low bits are undefined, so let's zero them
|
||||
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
|
||||
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
|
||||
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
|
||||
//// default is 12 bit resolution, 750 ms conversion time
|
||||
}
|
||||
celsius = (float)raw / 16.0;
|
||||
fahrenheit = celsius * 1.8 + 32.0;
|
||||
SerialUSB.print(" Temperature = ");
|
||||
SerialUSB.print(celsius);
|
||||
SerialUSB.print(" Celsius, ");
|
||||
SerialUSB.print(fahrenheit);
|
||||
SerialUSB.println(" Fahrenheit");
|
||||
}
|
||||
179
digistump-sam/libraries/DigiXEEPROM/Extensive_EEPROM.h
Normal file
179
digistump-sam/libraries/DigiXEEPROM/Extensive_EEPROM.h
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
Extensive TWI/I2C EEPROM Library - for 24LCxxx devices
|
||||
version: 0.4.1
|
||||
target device: Microchip 24LC256 or similar
|
||||
compatibility: designed with Arduino Due
|
||||
-> Ver. 0.4.1: Successfully tested with Arduino Uno R3 and Arduino Micro!
|
||||
author: Dennis Schweer (Inglorious Engineer)
|
||||
license: CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/deed.en)
|
||||
|
||||
Overview:
|
||||
-bytewise reading/writing
|
||||
void extEEPROMwrite(int chip_address, int address, byte value);
|
||||
byte extEEPROMread(int chip_address, int address);
|
||||
-pagewise reading/writing
|
||||
void extEEPROMwritePage(int chip_address, int startaddress, byte* data_origin_array, int amount_of_transfered_bytes)
|
||||
(!!!ATTENTION!!!: Limited to 30 Bytes only!)
|
||||
void extEEPROMreadPage(int chip_address, int startaddress, byte* data_target_array, int amount_of_transfered_bytes)
|
||||
(!!!ATTENTION!!!: Limited to 32 Bytes only)
|
||||
Do not care about their size, just save them!
|
||||
-read/write complete 32bit integers [Requires four bytes of your EEPROM.]
|
||||
void extEEPROMwriteInt(int chip_address, int address, int data_to_be_stored)
|
||||
int extEEPROMreadInt(int chip_address, int address)
|
||||
-read/write your 10/12 bit sensor values (e.g., ADC values) [Requires two bytes of your EEPROM.]
|
||||
void extEEPROMwriteSensor(int chip_address, int addresse, int data_to_be_stored)
|
||||
int extEEPROMreadSensor(int chip_address, int addresse)
|
||||
|
||||
NEW IN VERSION 0.4:
|
||||
Now all functions include a device address parameter, allowing you to use two
|
||||
or more external EEPROM chips simultaneously on a single bus. Just choose the
|
||||
right device addresses and feet them into the library functions!
|
||||
|
||||
NEW IN VERSION 0.4.1:
|
||||
My library is designed with an Arduino Due, but now everything is successfully
|
||||
tested to work on Arduino Uno R3 and Arduino Micro as well! Since all current
|
||||
Arduinos are based on either ATmega328 (e.g., Uno), ATmega32U4 (e.g., Micro/
|
||||
Leonardo/Esplora) or ATSAM3X8E (Due), my library should work with ALL official
|
||||
or 1:1-compatible boards.
|
||||
!!! Unfortunately, Arduino Due appears to be the only device with the ability
|
||||
to handle 32 bit integers. Hence none of my "writeInt" / "readInt" functions
|
||||
run on 8-bit Arduinos !!!
|
||||
|
||||
|
||||
Planned for future releases:
|
||||
-erase byte
|
||||
-erase page
|
||||
-erase complete EEPROM
|
||||
-read/write with autocorrection of "startaddress"-value
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
//========FUNCTIONS=========================
|
||||
|
||||
///////////////// WRITE /////////////////////
|
||||
|
||||
void extEEPROMwrite(int EEPROM_addr, int addr, byte data)
|
||||
{
|
||||
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
|
||||
Wire.write(highByte(addr)); // send high byte of address
|
||||
Wire.write(lowByte(addr)); // send low byte of address
|
||||
Wire.write((byte) data); // send data
|
||||
Wire.endTransmission(true); // stop transmitting
|
||||
delay(6); // wait for a successful write
|
||||
}
|
||||
|
||||
void extEEPROMwritePage(int EEPROM_addr, int addr, byte* data_origin, int amount)
|
||||
{
|
||||
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
|
||||
Wire.write(highByte(addr)); // send high byte of address
|
||||
Wire.write(lowByte(addr)); // send low byte of address
|
||||
for(int i = 0; i<amount; i++) //write array into EEPROM
|
||||
{
|
||||
Wire.write((byte) data_origin[i]);
|
||||
}
|
||||
Wire.endTransmission(true); // stop transmitting
|
||||
delay(6); // wait for a successful write
|
||||
}
|
||||
|
||||
void extEEPROMwriteInt(int EEPROM_addr, int addr, int data)
|
||||
{
|
||||
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
|
||||
Wire.write(highByte(addr)); // send high byte of address
|
||||
Wire.write(lowByte(addr)); // send low byte of address
|
||||
Wire.write(lowByte(data)); // send lowest byte of 32 bit integer
|
||||
data = data >> 8;
|
||||
Wire.write(lowByte(data)); // send 2nd lowest byte of 32 bit integer
|
||||
data = data >> 8;
|
||||
Wire.write(lowByte(data)); // send 2nd highest byte of 32 bit integer
|
||||
data = data >> 8;
|
||||
Wire.write(lowByte(data)); // send highest byte of 32 bit integer
|
||||
Wire.endTransmission(true); // stop transmitting
|
||||
delay(6); // wait for a successful write
|
||||
}
|
||||
|
||||
void extEEPROMwriteSensor(int EEPROM_addr, int addr, int data)
|
||||
{
|
||||
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
|
||||
Wire.write(highByte(addr)); // send high byte of address
|
||||
Wire.write(lowByte(addr)); // send low byte of address
|
||||
Wire.write(lowByte(data)); // send low byte of 12 bit integer
|
||||
data = data >> 8;
|
||||
Wire.write(lowByte(data)); // send high byte of 12 bit integer
|
||||
Wire.endTransmission(true); // stop transmitting
|
||||
delay(6); // wait for a successful write
|
||||
}
|
||||
|
||||
///////////////// READ /////////////////////
|
||||
|
||||
byte extEEPROMread(int EEPROM_addr, int addr)
|
||||
{
|
||||
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
|
||||
Wire.write(highByte(addr)); // send high byte of address
|
||||
Wire.write(lowByte(addr)); // send low byte of address
|
||||
Wire.endTransmission(true); // stop transmitting
|
||||
Wire.requestFrom(EEPROM_addr, 0x01, true); // request 1 byte form the device attached to EEPROM_addr
|
||||
byte data_out = 64;
|
||||
// read that byte
|
||||
while(Wire.available() == 0) {} // wait for data
|
||||
data_out = Wire.read(); //read single byte
|
||||
return data_out;
|
||||
}
|
||||
|
||||
void extEEPROMreadPage(int EEPROM_addr, int addr, byte* data_target, int amount)
|
||||
{
|
||||
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
|
||||
Wire.write(highByte(addr)); // send high byte of address
|
||||
Wire.write(lowByte(addr)); // send low byte of address
|
||||
Wire.endTransmission(true); // stop transmitting
|
||||
Wire.requestFrom(EEPROM_addr, amount, true); // request 1 byte form the device attached to EEPROM_addr
|
||||
// read that byte
|
||||
while(Wire.available() == 0) {} // wait for data
|
||||
for(int i = 0; i<amount; i++) //write data into array
|
||||
{
|
||||
data_target[i] = Wire.read();
|
||||
}
|
||||
}
|
||||
|
||||
int extEEPROMreadInt(int EEPROM_addr, int addr)
|
||||
{
|
||||
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
|
||||
Wire.write(highByte(addr)); // send high byte of address
|
||||
Wire.write(lowByte(addr)); // send low byte of address
|
||||
Wire.endTransmission(true); // stop transmitting
|
||||
Wire.requestFrom(EEPROM_addr, 0x04, true); // request 1 byte form the device attached to EEPROM_addr
|
||||
int data_out = 0xDEADBEEF;
|
||||
int temp = 0xDEADBEEF;
|
||||
// read that byte
|
||||
while(Wire.available() == 0) {} // wait for data
|
||||
data_out = Wire.read(); //read single byte
|
||||
//reconstruct value
|
||||
temp = Wire.read();
|
||||
temp = temp << 8;
|
||||
data_out = data_out | temp;
|
||||
temp = Wire.read();
|
||||
temp = temp << 16;
|
||||
data_out = data_out | temp;
|
||||
temp = Wire.read();
|
||||
temp = temp << 24;
|
||||
data_out = data_out | temp;
|
||||
return data_out;
|
||||
}
|
||||
|
||||
int extEEPROMreadSensor(int EEPROM_addr, int addr)
|
||||
{
|
||||
Wire.beginTransmission(EEPROM_addr); //Start transmission to EEPROM
|
||||
Wire.write(highByte(addr)); // send high byte of address
|
||||
Wire.write(lowByte(addr)); // send low byte of address
|
||||
Wire.endTransmission(true); // stop transmitting
|
||||
Wire.requestFrom(EEPROM_addr, 0x04, true); // request 1 byte form the device attached to EEPROM_addr
|
||||
int data_out = 0xDEAD;
|
||||
int temp = 0xBEEF;
|
||||
// read that byte
|
||||
while(Wire.available() == 0) {} // wait for data
|
||||
data_out = Wire.read(); //read single byte
|
||||
//reconstruct value
|
||||
temp = Wire.read();
|
||||
temp = temp << 8;
|
||||
data_out = data_out | temp;
|
||||
return data_out;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
Extensive TWI/I2C EEPROM Library - for 24LCxxx devices
|
||||
version: 0.4.1
|
||||
target device: Microchip 24LC256 or similar
|
||||
compatibility: designed with Arduino Due
|
||||
-> Ver. 0.4.1: Successfully tested with Arduino Uno R3 and Arduino Micro!
|
||||
author: Dennis Schweer (Inglorious Engineer)
|
||||
license: CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/deed.en)
|
||||
|
||||
Overview:
|
||||
-bytewise reading/writing
|
||||
void extEEPROMwrite(int chip_address, int address, byte value);
|
||||
byte extEEPROMread(int chip_address, int address);
|
||||
-pagewise reading/writing
|
||||
void extEEPROMwritePage(int chip_address, int startaddress, byte* data_origin_array, int amount_of_transfered_bytes)
|
||||
(!!!ATTENTION!!!: Limited to 30 Bytes only!)
|
||||
void extEEPROMreadPage(int chip_address, int startaddress, byte* data_target_array, int amount_of_transfered_bytes)
|
||||
(!!!ATTENTION!!!: Limited to 32 Bytes only)
|
||||
Do not care about their size, just save them!
|
||||
-read/write complete 32bit integers [Requires four bytes of your EEPROM.]
|
||||
void extEEPROMwriteInt(int chip_address, int address, int data_to_be_stored)
|
||||
int extEEPROMreadInt(int chip_address, int address)
|
||||
-read/write your 10/12 bit sensor values (e.g., ADC values) [Requires two bytes of your EEPROM.]
|
||||
void extEEPROMwriteSensor(int chip_address, int addresse, int data_to_be_stored)
|
||||
int extEEPROMreadSensor(int chip_address, int addresse)
|
||||
|
||||
NEW IN VERSION 0.4:
|
||||
Now all functions include a device address parameter, allowing you to use two
|
||||
or more external EEPROM chips simultaneously on a single bus. Just choose the
|
||||
right device addresses and feet them into the library functions!
|
||||
|
||||
NEW IN VERSION 0.4.1:
|
||||
My library is designed with an Arduino Due, but now everything is successfully
|
||||
tested to work on Arduino Uno R3 and Arduino Micro as well! Since all current
|
||||
Arduinos are based on either ATmega328 (e.g., Uno), ATmega32U4 (e.g., Micro/
|
||||
Leonardo/Esplora) or ATSAM3X8E (Due), my library should work with ALL official
|
||||
or 1:1-compatible boards.
|
||||
!!! Unfortunately, Arduino Due appears to be the only device with the ability
|
||||
to handle 32 bit integers. Hence none of my "writeInt" / "readInt" functions
|
||||
run on 8-bit Arduinos !!!
|
||||
|
||||
|
||||
Planned for future releases:
|
||||
-erase byte
|
||||
-erase page
|
||||
-erase complete EEPROM
|
||||
-read/write with autocorrection of "startaddress"-value
|
||||
*/
|
||||
#include <Wire.h>
|
||||
#include <Extensive_EEPROM.h>
|
||||
|
||||
const int EEPROM_addr = 0x50;
|
||||
|
||||
// Testbed variables
|
||||
int test = 1;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin(); // join i2c bus (address optional for master)
|
||||
Serial.begin(9600);
|
||||
test = 1;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//Testbed
|
||||
if(test == 1) //only run it once
|
||||
{
|
||||
//byte-wise writing/reading
|
||||
Serial.println("//byte-wise writing/reading");
|
||||
for(int i = 0; i < 32; i++)
|
||||
{
|
||||
extEEPROMwrite(EEPROM_addr, i, i); //void extEEPROMwrite(int chip_address, int address, byte value);
|
||||
}
|
||||
int data_back;
|
||||
for(int i = 0; i < 32; i++)
|
||||
{
|
||||
data_back = extEEPROMread(EEPROM_addr, i); //byte extEEPROMread(int chip_address, int address);
|
||||
Serial.print("original data= ");
|
||||
Serial.print(i);
|
||||
Serial.print(" read_back= ");
|
||||
Serial.println(data_back);
|
||||
}
|
||||
|
||||
|
||||
//page-wise writing/reading
|
||||
Serial.println("//page-wise writing/reading");
|
||||
byte data_to_be_written[30];
|
||||
for(int i=0; i<30; i++)
|
||||
{
|
||||
data_to_be_written[i] = (29-i); //writes the numbers 29 downto 0 into cells 0-29
|
||||
Serial.print("Original Data = ");
|
||||
Serial.println((29-i));
|
||||
}
|
||||
//store array in EEPROM (max. 30 Bytes)
|
||||
extEEPROMwritePage(EEPROM_addr, 32, data_to_be_written, 30); //void extEEPROMwritePage(int chip_address, int startaddress, byte* data_origin_array, int amount_of_transfered_bytes)
|
||||
//read page into an array (max. 32 Bytes)
|
||||
byte data_output[30];
|
||||
extEEPROMreadPage(EEPROM_addr, 32, data_output, 30); // void extEEPROMreadPage(int chip_address, int startaddress, byte* data_target_array, int amountof_transfered_bytes)
|
||||
for(int j=0; j<30; j++)
|
||||
{
|
||||
Serial.print("Read Page= ");
|
||||
Serial.println(data_output[j]); // Print array
|
||||
}
|
||||
|
||||
//write/read 32 bit integer
|
||||
Serial.println("//write/read 32 bit integer");
|
||||
int original_int = 0x7FFFFFFF;
|
||||
extEEPROMwriteInt(EEPROM_addr, 70, original_int);
|
||||
int original_int_output;
|
||||
original_int_output = extEEPROMreadInt(EEPROM_addr, 70);
|
||||
Serial.print("Integer: in = ");
|
||||
Serial.print(original_int);
|
||||
Serial.print(" / out = ");
|
||||
Serial.println(original_int_output);
|
||||
|
||||
//write/read 10/12 bit sensor data
|
||||
Serial.println("//write/read 10/12 bit sensor data");
|
||||
int original_sensor = 0x7FFF;
|
||||
extEEPROMwriteInt(EEPROM_addr, 75, original_sensor);
|
||||
int original_sensor_output;
|
||||
original_sensor_output = extEEPROMreadInt(EEPROM_addr, 75);
|
||||
Serial.print("Sensordata: in = ");
|
||||
Serial.print(original_sensor);
|
||||
Serial.print(" / out = ");
|
||||
Serial.println(original_sensor_output);
|
||||
|
||||
}
|
||||
test = 2; // only perform this procedure once
|
||||
}
|
||||
321
digistump-sam/libraries/DigiXLCD/LiquidCrystal_I2C.cpp
Normal file
321
digistump-sam/libraries/DigiXLCD/LiquidCrystal_I2C.cpp
Normal file
@@ -0,0 +1,321 @@
|
||||
// LiquidCrystal_I2C V2.0
|
||||
|
||||
#include "LiquidCrystal_I2C.h"
|
||||
#include <inttypes.h>
|
||||
#if defined(__AVR_ATtiny85__) || (__AVR_ATtiny2313__)
|
||||
#include "TinyWireM.h" // include this if ATtiny85 or ATtiny2313
|
||||
#else
|
||||
#include <Wire.h> // original lib include
|
||||
#endif
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
// When the display powers up, it is configured as follows:
|
||||
//
|
||||
// 1. Display clear
|
||||
// 2. Function set:
|
||||
// DL = 1; 8-bit interface data
|
||||
// N = 0; 1-line display
|
||||
// F = 0; 5x8 dot character font
|
||||
// 3. Display on/off control:
|
||||
// D = 0; Display off
|
||||
// C = 0; Cursor off
|
||||
// B = 0; Blinking off
|
||||
// 4. Entry mode set:
|
||||
// I/D = 1; Increment by 1
|
||||
// S = 0; No shift
|
||||
//
|
||||
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
|
||||
// can't assume that its in that state when a sketch starts (and the
|
||||
// LiquidCrystal constructor is called).
|
||||
|
||||
LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows)
|
||||
{
|
||||
_Addr = lcd_Addr;
|
||||
_cols = lcd_cols;
|
||||
_rows = lcd_rows;
|
||||
_backlightval = LCD_NOBACKLIGHT;
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::init(){
|
||||
init_priv();
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::init_priv()
|
||||
{
|
||||
#if defined (__AVR_ATtiny85__) || (__AVR_ATtiny2313__)
|
||||
TinyWireM.begin(); // initialize I2C lib
|
||||
#else // original call
|
||||
Wire1.begin();
|
||||
#endif
|
||||
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
|
||||
begin(_cols, _rows);
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
||||
if (lines > 1) {
|
||||
_displayfunction |= LCD_2LINE;
|
||||
}
|
||||
_numlines = lines;
|
||||
|
||||
// for some 1 line displays you can select a 10 pixel high font
|
||||
if ((dotsize != 0) && (lines == 1)) {
|
||||
_displayfunction |= LCD_5x10DOTS;
|
||||
}
|
||||
|
||||
// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
|
||||
// according to datasheet, we need at least 40ms after power rises above 2.7V
|
||||
// before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
|
||||
delay(50);
|
||||
|
||||
// Now we pull both RS and R/W low to begin commands
|
||||
expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1)
|
||||
delay(1000);
|
||||
|
||||
//put the LCD into 4 bit mode
|
||||
// this is according to the hitachi HD44780 datasheet
|
||||
// figure 24, pg 46
|
||||
|
||||
// we start in 8bit mode, try to set 4 bit mode
|
||||
write4bits(0x03 << 4);
|
||||
delayMicroseconds(4500); // wait min 4.1ms
|
||||
|
||||
// second try
|
||||
write4bits(0x03 << 4);
|
||||
delayMicroseconds(4500); // wait min 4.1ms
|
||||
|
||||
// third go!
|
||||
write4bits(0x03 << 4);
|
||||
delayMicroseconds(150);
|
||||
|
||||
// finally, set to 4-bit interface
|
||||
write4bits(0x02 << 4);
|
||||
|
||||
|
||||
|
||||
// set # lines, font size, etc.
|
||||
command(LCD_FUNCTIONSET | _displayfunction);
|
||||
|
||||
// turn the display on with no cursor or blinking default
|
||||
_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;
|
||||
display();
|
||||
|
||||
// clear it off
|
||||
clear();
|
||||
|
||||
// Initialize to default text direction (for roman languages)
|
||||
_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
|
||||
|
||||
// set the entry mode
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
|
||||
home();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********** high level commands, for the user! */
|
||||
void LiquidCrystal_I2C::clear(){
|
||||
command(LCD_CLEARDISPLAY);// clear display, set cursor position to zero
|
||||
delayMicroseconds(2000); // this command takes a long time!
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::home(){
|
||||
command(LCD_RETURNHOME); // set cursor position to zero
|
||||
delayMicroseconds(2000); // this command takes a long time!
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){
|
||||
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
|
||||
if ( row > _numlines ) {
|
||||
row = _numlines-1; // we count rows starting w/0
|
||||
}
|
||||
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
|
||||
}
|
||||
|
||||
// Turn the display on/off (quickly)
|
||||
void LiquidCrystal_I2C::noDisplay() {
|
||||
_displaycontrol &= ~LCD_DISPLAYON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal_I2C::display() {
|
||||
_displaycontrol |= LCD_DISPLAYON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// Turns the underline cursor on/off
|
||||
void LiquidCrystal_I2C::noCursor() {
|
||||
_displaycontrol &= ~LCD_CURSORON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal_I2C::cursor() {
|
||||
_displaycontrol |= LCD_CURSORON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// Turn on and off the blinking cursor
|
||||
void LiquidCrystal_I2C::noBlink() {
|
||||
_displaycontrol &= ~LCD_BLINKON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal_I2C::blink() {
|
||||
_displaycontrol |= LCD_BLINKON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// These commands scroll the display without changing the RAM
|
||||
void LiquidCrystal_I2C::scrollDisplayLeft(void) {
|
||||
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
|
||||
}
|
||||
void LiquidCrystal_I2C::scrollDisplayRight(void) {
|
||||
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
|
||||
}
|
||||
|
||||
// This is for text that flows Left to Right
|
||||
void LiquidCrystal_I2C::leftToRight(void) {
|
||||
_displaymode |= LCD_ENTRYLEFT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This is for text that flows Right to Left
|
||||
void LiquidCrystal_I2C::rightToLeft(void) {
|
||||
_displaymode &= ~LCD_ENTRYLEFT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This will 'right justify' text from the cursor
|
||||
void LiquidCrystal_I2C::autoscroll(void) {
|
||||
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This will 'left justify' text from the cursor
|
||||
void LiquidCrystal_I2C::noAutoscroll(void) {
|
||||
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// Allows us to fill the first 8 CGRAM locations
|
||||
// with custom characters
|
||||
void LiquidCrystal_I2C::createChar(uint8_t location, uint8_t charmap[]) {
|
||||
location &= 0x7; // we only have 8 locations 0-7
|
||||
command(LCD_SETCGRAMADDR | (location << 3));
|
||||
for (int i=0; i<8; i++) {
|
||||
write(charmap[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Turn the (optional) backlight off/on
|
||||
void LiquidCrystal_I2C::noBacklight(void) {
|
||||
_backlightval=LCD_NOBACKLIGHT;
|
||||
expanderWrite(0);
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::backlight(void) {
|
||||
_backlightval=LCD_BACKLIGHT;
|
||||
expanderWrite(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********** mid level commands, for sending data/cmds */
|
||||
|
||||
inline void LiquidCrystal_I2C::command(uint8_t value) {
|
||||
send(value, 0);
|
||||
}
|
||||
|
||||
inline size_t LiquidCrystal_I2C::write(uint8_t value) {
|
||||
send(value, Rs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/************ low level data pushing commands **********/
|
||||
|
||||
// write either command or data
|
||||
void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) {
|
||||
uint8_t highnib=value&0xf0;
|
||||
uint8_t lownib=(value<<4)&0xf0;
|
||||
write4bits((highnib)|mode);
|
||||
write4bits((lownib)|mode);
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::write4bits(uint8_t value) {
|
||||
expanderWrite(value);
|
||||
pulseEnable(value);
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::expanderWrite(uint8_t _data){
|
||||
#if defined(__AVR_ATtiny85__) || (__AVR_ATtiny2313__) // Replaced Wire calls with ATtiny TWI calls
|
||||
TinyWireM.beginTransmission(_Addr);
|
||||
TinyWireM.send(((int)(_data) | _backlightval));
|
||||
TinyWireM.endTransmission();
|
||||
#else // original lib function
|
||||
Wire1.beginTransmission(_Addr);
|
||||
Wire1.write((int)(_data) | _backlightval);
|
||||
Wire1.endTransmission();
|
||||
#endif
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::pulseEnable(uint8_t _data){
|
||||
expanderWrite(_data | En); // En high
|
||||
delayMicroseconds(1); // enable pulse must be >450ns
|
||||
|
||||
expanderWrite(_data & ~En); // En low
|
||||
delayMicroseconds(50); // commands need > 37us to settle
|
||||
}
|
||||
|
||||
|
||||
// Alias functions
|
||||
|
||||
void LiquidCrystal_I2C::cursor_on(){
|
||||
cursor();
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::cursor_off(){
|
||||
noCursor();
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::blink_on(){
|
||||
blink();
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::blink_off(){
|
||||
noBlink();
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::load_custom_character(uint8_t char_num, uint8_t *rows){
|
||||
createChar(char_num, rows);
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::setBacklight(uint8_t new_val){
|
||||
if(new_val){
|
||||
backlight(); // turn backlight on
|
||||
}else{
|
||||
noBacklight(); // turn backlight off
|
||||
}
|
||||
}
|
||||
|
||||
void LiquidCrystal_I2C::printstr(const char c[]){
|
||||
//This function is not identical to the function used for "real" I2C displays
|
||||
//it's here so the user sketch doesn't have to be changed
|
||||
print(c);
|
||||
}
|
||||
|
||||
|
||||
// unsupported API functions
|
||||
void LiquidCrystal_I2C::off(){}
|
||||
void LiquidCrystal_I2C::on(){}
|
||||
void LiquidCrystal_I2C::setDelay (int cmdDelay,int charDelay) {}
|
||||
uint8_t LiquidCrystal_I2C::status(){return 0;}
|
||||
uint8_t LiquidCrystal_I2C::keypad (){return 0;}
|
||||
uint8_t LiquidCrystal_I2C::init_bargraph(uint8_t graphtype){return 0;}
|
||||
void LiquidCrystal_I2C::draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end){}
|
||||
void LiquidCrystal_I2C::draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_row_end){}
|
||||
void LiquidCrystal_I2C::setContrast(uint8_t new_val){}
|
||||
|
||||
|
||||
135
digistump-sam/libraries/DigiXLCD/LiquidCrystal_I2C.h
Normal file
135
digistump-sam/libraries/DigiXLCD/LiquidCrystal_I2C.h
Normal file
@@ -0,0 +1,135 @@
|
||||
// LiquidCrystal_I2C V2.0
|
||||
// Note: The original libe file has beem modified to support the ATtiny85 1/20/11 by "BroHogan"
|
||||
// All changes can be located by searching for "__AVR_ATtiny85__".
|
||||
|
||||
#ifndef LiquidCrystal_I2C_h
|
||||
#define LiquidCrystal_I2C_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "Print.h"
|
||||
|
||||
#if defined(__AVR_ATtiny85__) || (__AVR_ATtiny2313__)
|
||||
#include "TinyWireM.h" // include this if ATtiny85 or ATtiny2313
|
||||
#else
|
||||
#include <Wire.h> // original lib include
|
||||
#endif
|
||||
|
||||
|
||||
// commands
|
||||
#define LCD_CLEARDISPLAY 0x01
|
||||
#define LCD_RETURNHOME 0x02
|
||||
#define LCD_ENTRYMODESET 0x04
|
||||
#define LCD_DISPLAYCONTROL 0x08
|
||||
#define LCD_CURSORSHIFT 0x10
|
||||
#define LCD_FUNCTIONSET 0x20
|
||||
#define LCD_SETCGRAMADDR 0x40
|
||||
#define LCD_SETDDRAMADDR 0x80
|
||||
|
||||
// flags for display entry mode
|
||||
#define LCD_ENTRYRIGHT 0x00
|
||||
#define LCD_ENTRYLEFT 0x02
|
||||
#define LCD_ENTRYSHIFTINCREMENT 0x01
|
||||
#define LCD_ENTRYSHIFTDECREMENT 0x00
|
||||
|
||||
// flags for display on/off control
|
||||
#define LCD_DISPLAYON 0x04
|
||||
#define LCD_DISPLAYOFF 0x00
|
||||
#define LCD_CURSORON 0x02
|
||||
#define LCD_CURSOROFF 0x00
|
||||
#define LCD_BLINKON 0x01
|
||||
#define LCD_BLINKOFF 0x00
|
||||
|
||||
// flags for display/cursor shift
|
||||
#define LCD_DISPLAYMOVE 0x08
|
||||
#define LCD_CURSORMOVE 0x00
|
||||
#define LCD_MOVERIGHT 0x04
|
||||
#define LCD_MOVELEFT 0x00
|
||||
|
||||
// flags for function set
|
||||
#define LCD_8BITMODE 0x10
|
||||
#define LCD_4BITMODE 0x00
|
||||
#define LCD_2LINE 0x08
|
||||
#define LCD_1LINE 0x00
|
||||
#define LCD_5x10DOTS 0x04
|
||||
#define LCD_5x8DOTS 0x00
|
||||
|
||||
// flags for backlight control
|
||||
#define LCD_BACKLIGHT 0x08
|
||||
#define LCD_NOBACKLIGHT 0x00
|
||||
|
||||
#define En B00000100 // Enable bit
|
||||
#define Rw B00000010 // Read/Write bit
|
||||
#define Rs B00000001 // Register select bit
|
||||
|
||||
class LiquidCrystal_I2C : public Print {
|
||||
public:
|
||||
LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);
|
||||
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
|
||||
void clear();
|
||||
void home();
|
||||
void noDisplay();
|
||||
void display();
|
||||
void noBlink();
|
||||
void blink();
|
||||
void noCursor();
|
||||
void cursor();
|
||||
void scrollDisplayLeft();
|
||||
void scrollDisplayRight();
|
||||
void printLeft();
|
||||
void printRight();
|
||||
void leftToRight();
|
||||
void rightToLeft();
|
||||
void shiftIncrement();
|
||||
void shiftDecrement();
|
||||
void noBacklight();
|
||||
void backlight();
|
||||
void autoscroll();
|
||||
void noAutoscroll();
|
||||
void createChar(uint8_t, uint8_t[]);
|
||||
void setCursor(uint8_t, uint8_t);
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
virtual size_t write(uint8_t);
|
||||
#else
|
||||
virtual void write(uint8_t);
|
||||
#endif
|
||||
void command(uint8_t);
|
||||
void init();
|
||||
|
||||
////compatibility API function aliases
|
||||
void blink_on(); // alias for blink()
|
||||
void blink_off(); // alias for noBlink()
|
||||
void cursor_on(); // alias for cursor()
|
||||
void cursor_off(); // alias for noCursor()
|
||||
void setBacklight(uint8_t new_val); // alias for backlight() and nobacklight()
|
||||
void load_custom_character(uint8_t char_num, uint8_t *rows); // alias for createChar()
|
||||
void printstr(const char[]);
|
||||
|
||||
////Unsupported API functions (not implemented in this library)
|
||||
uint8_t status();
|
||||
void setContrast(uint8_t new_val);
|
||||
uint8_t keypad();
|
||||
void setDelay(int,int);
|
||||
void on();
|
||||
void off();
|
||||
uint8_t init_bargraph(uint8_t graphtype);
|
||||
void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end);
|
||||
void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end);
|
||||
|
||||
|
||||
private:
|
||||
void init_priv();
|
||||
void send(uint8_t, uint8_t);
|
||||
void write4bits(uint8_t);
|
||||
void expanderWrite(uint8_t);
|
||||
void pulseEnable(uint8_t);
|
||||
uint8_t _Addr;
|
||||
uint8_t _displayfunction;
|
||||
uint8_t _displaycontrol;
|
||||
uint8_t _displaymode;
|
||||
uint8_t _numlines;
|
||||
uint8_t _cols;
|
||||
uint8_t _rows;
|
||||
uint8_t _backlightval;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
/* ATtiny85 as an I2C Master Ex2 BroHogan 1/21/11
|
||||
* Modified for Digistump/DigiX - Digispark LCD Shield by Erik Kettenburg 11/2012
|
||||
*/
|
||||
|
||||
//#define DEBUG
|
||||
#include <Wire.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos
|
||||
#include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85
|
||||
|
||||
#define GPIO_ADDR 0x27 // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A - 0x27 is the address of the Digispark LCD modules.
|
||||
|
||||
|
||||
LiquidCrystal_I2C lcd(GPIO_ADDR,16,2); // set address & 16 chars / 2 lines
|
||||
|
||||
|
||||
void setup(){
|
||||
Wire1.begin(); // initialize I2C lib - comment this out to use with standard arduinos
|
||||
lcd.init(); // initialize the lcd
|
||||
lcd.backlight();
|
||||
lcd.print("DigiX!"); // Print a message to the LCD.
|
||||
}
|
||||
|
||||
|
||||
void loop(){
|
||||
|
||||
}
|
||||
|
||||
BIN
digistump-sam/libraries/DigiXLCD/info/BC557.pdf
Normal file
BIN
digistump-sam/libraries/DigiXLCD/info/BC557.pdf
Normal file
Binary file not shown.
BIN
digistump-sam/libraries/DigiXLCD/info/Image.jpg
Normal file
BIN
digistump-sam/libraries/DigiXLCD/info/Image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
BIN
digistump-sam/libraries/DigiXLCD/info/PCF8574P.pdf
Normal file
BIN
digistump-sam/libraries/DigiXLCD/info/PCF8574P.pdf
Normal file
Binary file not shown.
BIN
digistump-sam/libraries/DigiXLCD/info/Schematic_diagram.jpg
Normal file
BIN
digistump-sam/libraries/DigiXLCD/info/Schematic_diagram.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 192 KiB |
@@ -0,0 +1,55 @@
|
||||
Notes for users with a Pollin.de interface board
|
||||
http://www.pollin.de/shop/dt/NDU4OTgxOTk-/Bausaetze_Module/Bausaetze/LCD_I2C_Modul.html
|
||||
|
||||
The pollin interface board will not work with de default library.
|
||||
To get it working two control lines to the LCD need to be changed.
|
||||
|
||||
Open file "LiquidCrystal_I2C.h" with a text editor like Notepad (not WordPad !)
|
||||
|
||||
In that file look for:
|
||||
#define En B00010000 // Enable bit
|
||||
#define Rw B00100000 // Read/Write bit
|
||||
#define Rs B01000000 // Register select bit
|
||||
|
||||
Replace these lines by:
|
||||
#define En B01000000 // Enable bit
|
||||
#define Rw B00100000 // Read/Write bit
|
||||
#define Rs B00010000 // Register select bit
|
||||
|
||||
|
||||
|
||||
People at Pollin also have misunderstood the PCF8574 Datasheet and list the wrong addresses on their PCB
|
||||
For PCF8574A the addressing is:
|
||||
|
||||
Jp3 Jp2 Jp1
|
||||
A2 A1 A0 Dec Hex
|
||||
L L L 56 0x38
|
||||
L L H 57 0x39
|
||||
L H L 64 0x40
|
||||
L H H 74 0x4A
|
||||
H L L 75 0x4B
|
||||
H L H 76 0x4C
|
||||
H H L 77 0x4D
|
||||
H H H 78 0x4E
|
||||
|
||||
They also seem to ship boards with a PCF8574
|
||||
For PCF8574 the addressing is:
|
||||
|
||||
Jp3 Jp2 Jp1
|
||||
A2 A1 A0 Dec Hex
|
||||
L L L 32 0x20
|
||||
L L H 33 0x21
|
||||
L H L 34 0x22
|
||||
L H H 35 0x23
|
||||
H L L 36 0x24
|
||||
H L H 37 0x25
|
||||
H H L 38 0x26
|
||||
H H H 39 0x27
|
||||
|
||||
|
||||
They have also chosen two rather high pull-up resistors (10K) for the I2C lines. Usually two 4K7 resistors should do the job.
|
||||
Please note that on a I2C bus only one device should have the pull-up resistors installed!
|
||||
|
||||
I hope this helps in getting your LCD working.
|
||||
|
||||
Mario
|
||||
36
digistump-sam/libraries/DigiXLCD/info/readme.txt
Normal file
36
digistump-sam/libraries/DigiXLCD/info/readme.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
LiquidCrystal_I2C V2.0
|
||||
|
||||
The LiquidCrystal_I2C library is a modified version of the standard LiquidCrystal library as found on
|
||||
the Arduino website.
|
||||
This library is intended to be used when a parallel HD44780 compatible LCD is controlled over I2C using
|
||||
a PCF8574 extender (see datasheet for details).
|
||||
4 of the 8 outputs are used for LDC data lines 4 to 7.
|
||||
3 outputs are used for the Enable, register-select and Read/Write lines.
|
||||
The one output left can be used to control the backlight of the LCD (if available).
|
||||
For backlight control some extra resistors and a pnp-type transistor are required (for details see
|
||||
schematic diagram).
|
||||
|
||||
The PCF8574 extender is available in two versions, the PCF8574 and the PCF8574A.
|
||||
The only difference between the two is the I2C base address.
|
||||
The base address for the PCF8574 is 0x20 and the base address for the PCF8574A is 0x38.
|
||||
The examples included in this zip file assume the use of an PCF8574 set for address 0x20
|
||||
(A0, A1 and A3 grounded).
|
||||
|
||||
For compatibility reasons this library contains some aliases for functions that are known under different
|
||||
names in other libraries. This should make it fairly easy to implement the library in existing sketches
|
||||
without changing to much code.
|
||||
Functions not supported by this library will return nothing at all and in case a return value is expected
|
||||
the function will return 0.
|
||||
|
||||
Update 8-12-2011:
|
||||
Due to the relaese of Arduino IDE 1.0 some changes were made to the library to get it working under the new IDE.
|
||||
Because of these changes this version of the LiquidCrystal_I2C library can not be used for older IDE versions.
|
||||
The old version of the LiquidCrystal_I2Clibrary can be downloaded form http://www.xs4all.nl/~hmario/arduino/LiquidCrystal_I2C/V1.0/LiquidCrystal_I2C_V1.0.zip
|
||||
|
||||
Download the latest version from:
|
||||
http://www.xs4all.nl/~hmario/arduino/LiquidCrystal_I2C/LiquidCrystal_I2C.zip
|
||||
(Thanks to Ailton F. for beta testing.)
|
||||
|
||||
|
||||
Mario H.
|
||||
atmega@xs4all.nl
|
||||
47
digistump-sam/libraries/DigiXLCD/keywords.txt
Normal file
47
digistump-sam/libraries/DigiXLCD/keywords.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
###########################################
|
||||
# Syntax Coloring Map For LiquidCrystal_I2C
|
||||
# Version 2.0
|
||||
###########################################
|
||||
|
||||
###########################################
|
||||
# Datatypes (KEYWORD1)
|
||||
###########################################
|
||||
|
||||
LiquidCrystal_I2C KEYWORD1
|
||||
|
||||
###########################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
###########################################
|
||||
init KEYWORD2
|
||||
begin KEYWORD2
|
||||
clear KEYWORD2
|
||||
home KEYWORD2
|
||||
noDisplay KEYWORD2
|
||||
display KEYWORD2
|
||||
noBlink KEYWORD2
|
||||
blink KEYWORD2
|
||||
noCursor KEYWORD2
|
||||
cursor KEYWORD2
|
||||
scrollDisplayLeft KEYWORD2
|
||||
scrollDisplayRight KEYWORD2
|
||||
leftToRight KEYWORD2
|
||||
rightToLeft KEYWORD2
|
||||
shiftIncrement KEYWORD2
|
||||
shiftDecrement KEYWORD2
|
||||
noBacklight KEYWORD2
|
||||
backlight KEYWORD2
|
||||
autoscroll KEYWORD2
|
||||
noAutoscroll KEYWORD2
|
||||
createChar KEYWORD2
|
||||
setCursor KEYWORD2
|
||||
print KEYWORD2
|
||||
blink_on KEYWORD2
|
||||
blink_off KEYWORD2
|
||||
cursor_on KEYWORD2
|
||||
cursor_off KEYWORD2
|
||||
setBacklight KEYWORD2
|
||||
load_custom_character KEYWORD2
|
||||
printstr KEYWORD2
|
||||
###########################################
|
||||
# Constants (LITERAL1)
|
||||
###########################################
|
||||
1405
digistump-sam/libraries/I2Cdev/I2Cdev.cpp
Normal file
1405
digistump-sam/libraries/I2Cdev/I2Cdev.cpp
Normal file
File diff suppressed because it is too large
Load Diff
268
digistump-sam/libraries/I2Cdev/I2Cdev.h
Normal file
268
digistump-sam/libraries/I2Cdev/I2Cdev.h
Normal file
@@ -0,0 +1,268 @@
|
||||
// I2Cdev library collection - Main I2C device class header file
|
||||
// Abstracts bit and byte I2C R/W functions into a convenient class
|
||||
// 6/9/2012 by Jeff Rowberg <jeff@rowberg.net>
|
||||
//
|
||||
// Changelog:
|
||||
// 2013-05-05 - fix issue with writing bit values to words (Sasquatch/Farzanegan)
|
||||
// 2012-06-09 - fix major issue with reading > 32 bytes at a time with Arduino Wire
|
||||
// - add compiler warnings when using outdated or IDE or limited I2Cdev implementation
|
||||
// 2011-11-01 - fix write*Bits mask calculation (thanks sasquatch @ Arduino forums)
|
||||
// 2011-10-03 - added automatic Arduino version detection for ease of use
|
||||
// 2011-10-02 - added Gene Knight's NBWire TwoWire class implementation with small modifications
|
||||
// 2011-08-31 - added support for Arduino 1.0 Wire library (methods are different from 0.x)
|
||||
// 2011-08-03 - added optional timeout parameter to read* methods to easily change from default
|
||||
// 2011-08-02 - added support for 16-bit registers
|
||||
// - fixed incorrect Doxygen comments on some methods
|
||||
// - added timeout value for read operations (thanks mem @ Arduino forums)
|
||||
// 2011-07-30 - changed read/write function structures to return success or byte counts
|
||||
// - made all methods static for multi-device memory savings
|
||||
// 2011-07-28 - initial release
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
#ifndef _I2CDEV_H_
|
||||
#define _I2CDEV_H_
|
||||
|
||||
// comment this out if you are using a non-optimal IDE/implementation setting
|
||||
// but want the compiler to shut up about it
|
||||
#define I2CDEV_IMPLEMENTATION_WARNINGS
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// I2C interface implementation options
|
||||
// -----------------------------------------------------------------------------
|
||||
#define I2CDEV_ARDUINO_WIRE 1 // Wire object from Arduino
|
||||
#define I2CDEV_BUILTIN_NBWIRE 2 // Tweaked Wire object from Gene Knight's NBWire project
|
||||
// ^^^ NBWire implementation is still buggy w/some interrupts!
|
||||
#define I2CDEV_BUILTIN_FASTWIRE 3 // FastWire object from Francesco Ferrara's project
|
||||
// ^^^ FastWire implementation in I2Cdev is INCOMPLETE!
|
||||
#define I2CDEV_I2CMASTER_LIBRARY 4 // I2C object from DSSCircuits I2C-Master Library at
|
||||
// https://github.com/DSSCircuits/I2C-Master-Library
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// I2C interface implementation setting
|
||||
// -----------------------------------------------------------------------------
|
||||
#define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Arduino-style "Serial.print" debug constant (uncomment to enable)
|
||||
// -----------------------------------------------------------------------------
|
||||
//#define I2CDEV_SERIAL_DEBUG
|
||||
|
||||
#ifdef ARDUINO
|
||||
#if ARDUINO < 100
|
||||
#include "WProgram.h"
|
||||
#else
|
||||
#include "Arduino.h"
|
||||
#endif
|
||||
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
|
||||
#include <Wire.h>
|
||||
#else
|
||||
#if I2CDEV_IMPLEMENTATION == I2CDEV_I2CMASTER_LIBRARY
|
||||
#include <I2C.h>
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#include "ArduinoWrapper.h"
|
||||
#endif
|
||||
|
||||
// 1000ms default read timeout (modify with "I2Cdev::readTimeout = [ms];")
|
||||
#define I2CDEV_DEFAULT_READ_TIMEOUT 1000
|
||||
|
||||
class I2Cdev {
|
||||
public:
|
||||
I2Cdev();
|
||||
|
||||
static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
|
||||
static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
|
||||
static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
|
||||
static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
|
||||
static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
|
||||
static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
|
||||
static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
|
||||
static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
|
||||
|
||||
static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data);
|
||||
static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
|
||||
static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data);
|
||||
static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
|
||||
static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data);
|
||||
static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
|
||||
static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data);
|
||||
static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data);
|
||||
|
||||
static uint16_t readTimeout;
|
||||
};
|
||||
|
||||
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
|
||||
//////////////////////
|
||||
// FastWire 0.2
|
||||
// This is a library to help faster programs to read I2C devices.
|
||||
// Copyright(C) 2011
|
||||
// Francesco Ferrara
|
||||
//////////////////////
|
||||
|
||||
/* Master */
|
||||
#define TW_START 0x08
|
||||
#define TW_REP_START 0x10
|
||||
|
||||
/* Master Transmitter */
|
||||
#define TW_MT_SLA_ACK 0x18
|
||||
#define TW_MT_SLA_NACK 0x20
|
||||
#define TW_MT_DATA_ACK 0x28
|
||||
#define TW_MT_DATA_NACK 0x30
|
||||
#define TW_MT_ARB_LOST 0x38
|
||||
|
||||
/* Master Receiver */
|
||||
#define TW_MR_ARB_LOST 0x38
|
||||
#define TW_MR_SLA_ACK 0x40
|
||||
#define TW_MR_SLA_NACK 0x48
|
||||
#define TW_MR_DATA_ACK 0x50
|
||||
#define TW_MR_DATA_NACK 0x58
|
||||
|
||||
#define TW_OK 0
|
||||
#define TW_ERROR 1
|
||||
|
||||
class Fastwire {
|
||||
private:
|
||||
static boolean waitInt();
|
||||
|
||||
public:
|
||||
static void setup(int khz, boolean pullup);
|
||||
static byte write(byte device, byte address, byte value);
|
||||
static byte readBuf(byte device, byte address, byte *data, byte num);
|
||||
};
|
||||
#endif
|
||||
|
||||
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE
|
||||
// NBWire implementation based heavily on code by Gene Knight <Gene@Telobot.com>
|
||||
// Originally posted on the Arduino forum at http://arduino.cc/forum/index.php/topic,70705.0.html
|
||||
// Originally offered to the i2cdevlib project at http://arduino.cc/forum/index.php/topic,68210.30.html
|
||||
|
||||
#define NBWIRE_BUFFER_LENGTH 32
|
||||
|
||||
class TwoWire {
|
||||
private:
|
||||
static uint8_t rxBuffer[];
|
||||
static uint8_t rxBufferIndex;
|
||||
static uint8_t rxBufferLength;
|
||||
|
||||
static uint8_t txAddress;
|
||||
static uint8_t txBuffer[];
|
||||
static uint8_t txBufferIndex;
|
||||
static uint8_t txBufferLength;
|
||||
|
||||
// static uint8_t transmitting;
|
||||
static void (*user_onRequest)(void);
|
||||
static void (*user_onReceive)(int);
|
||||
static void onRequestService(void);
|
||||
static void onReceiveService(uint8_t*, int);
|
||||
|
||||
public:
|
||||
TwoWire();
|
||||
void begin();
|
||||
void begin(uint8_t);
|
||||
void begin(int);
|
||||
void beginTransmission(uint8_t);
|
||||
//void beginTransmission(int);
|
||||
uint8_t endTransmission(uint16_t timeout=0);
|
||||
void nbendTransmission(void (*function)(int)) ;
|
||||
uint8_t requestFrom(uint8_t, int, uint16_t timeout=0);
|
||||
//uint8_t requestFrom(int, int);
|
||||
void nbrequestFrom(uint8_t, int, void (*function)(int));
|
||||
void send(uint8_t);
|
||||
void send(uint8_t*, uint8_t);
|
||||
//void send(int);
|
||||
void send(char*);
|
||||
uint8_t available(void);
|
||||
uint8_t receive(void);
|
||||
void onReceive(void (*)(int));
|
||||
void onRequest(void (*)(void));
|
||||
};
|
||||
|
||||
#define TWI_READY 0
|
||||
#define TWI_MRX 1
|
||||
#define TWI_MTX 2
|
||||
#define TWI_SRX 3
|
||||
#define TWI_STX 4
|
||||
|
||||
#define TW_WRITE 0
|
||||
#define TW_READ 1
|
||||
|
||||
#define TW_MT_SLA_NACK 0x20
|
||||
#define TW_MT_DATA_NACK 0x30
|
||||
|
||||
#define CPU_FREQ 16000000L
|
||||
#define TWI_FREQ 100000L
|
||||
#define TWI_BUFFER_LENGTH 32
|
||||
|
||||
/* TWI Status is in TWSR, in the top 5 bits: TWS7 - TWS3 */
|
||||
|
||||
#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))
|
||||
#define TW_STATUS (TWSR & TW_STATUS_MASK)
|
||||
#define TW_START 0x08
|
||||
#define TW_REP_START 0x10
|
||||
#define TW_MT_SLA_ACK 0x18
|
||||
#define TW_MT_SLA_NACK 0x20
|
||||
#define TW_MT_DATA_ACK 0x28
|
||||
#define TW_MT_DATA_NACK 0x30
|
||||
#define TW_MT_ARB_LOST 0x38
|
||||
#define TW_MR_ARB_LOST 0x38
|
||||
#define TW_MR_SLA_ACK 0x40
|
||||
#define TW_MR_SLA_NACK 0x48
|
||||
#define TW_MR_DATA_ACK 0x50
|
||||
#define TW_MR_DATA_NACK 0x58
|
||||
#define TW_ST_SLA_ACK 0xA8
|
||||
#define TW_ST_ARB_LOST_SLA_ACK 0xB0
|
||||
#define TW_ST_DATA_ACK 0xB8
|
||||
#define TW_ST_DATA_NACK 0xC0
|
||||
#define TW_ST_LAST_DATA 0xC8
|
||||
#define TW_SR_SLA_ACK 0x60
|
||||
#define TW_SR_ARB_LOST_SLA_ACK 0x68
|
||||
#define TW_SR_GCALL_ACK 0x70
|
||||
#define TW_SR_ARB_LOST_GCALL_ACK 0x78
|
||||
#define TW_SR_DATA_ACK 0x80
|
||||
#define TW_SR_DATA_NACK 0x88
|
||||
#define TW_SR_GCALL_DATA_ACK 0x90
|
||||
#define TW_SR_GCALL_DATA_NACK 0x98
|
||||
#define TW_SR_STOP 0xA0
|
||||
#define TW_NO_INFO 0xF8
|
||||
#define TW_BUS_ERROR 0x00
|
||||
|
||||
//#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
|
||||
//#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr))
|
||||
|
||||
#ifndef sbi // set bit
|
||||
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
|
||||
#endif // sbi
|
||||
|
||||
#ifndef cbi // clear bit
|
||||
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
|
||||
#endif // cbi
|
||||
|
||||
extern TwoWire Wire;
|
||||
|
||||
#endif // I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE
|
||||
|
||||
#endif /* _I2CDEV_H_ */
|
||||
38
digistump-sam/libraries/I2Cdev/keywords.txt
Normal file
38
digistump-sam/libraries/I2Cdev/keywords.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For I2Cdev
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
I2Cdev KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
readBit KEYWORD2
|
||||
readBitW KEYWORD2
|
||||
readBits KEYWORD2
|
||||
readBitsW KEYWORD2
|
||||
readByte KEYWORD2
|
||||
readBytes KEYWORD2
|
||||
readWord KEYWORD2
|
||||
readWords KEYWORD2
|
||||
writeBit KEYWORD2
|
||||
writeBitW KEYWORD2
|
||||
writeBits KEYWORD2
|
||||
writeBitsW KEYWORD2
|
||||
writeByte KEYWORD2
|
||||
writeBytes KEYWORD2
|
||||
writeWord KEYWORD2
|
||||
writeWords KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
@@ -0,0 +1,356 @@
|
||||
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class using DMP (MotionApps v2.0)
|
||||
// 6/21/2012 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// 2012-06-21 - added note about Arduino 1.0.1 + Leonardo compatibility error
|
||||
// 2012-06-20 - improved FIFO overflow handling and simplified read process
|
||||
// 2012-06-19 - completely rearranged DMP initialization code and simplification
|
||||
// 2012-06-13 - pull gyro and accel data from FIFO packet instead of reading directly
|
||||
// 2012-06-09 - fix broken FIFO read sequence and change interrupt detection to RISING
|
||||
// 2012-06-05 - add gravity-compensated initial reference frame acceleration output
|
||||
// - add 3D math helper file to DMP6 example sketch
|
||||
// - add Euler output and Yaw/Pitch/Roll output formats
|
||||
// 2012-06-04 - remove accel offset clearing for better results (thanks Sungon Lee)
|
||||
// 2012-06-01 - fixed gyro sensitivity to be 2000 deg/sec instead of 250
|
||||
// 2012-05-30 - basic DMP initialization working
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
|
||||
// is used in I2Cdev.h
|
||||
#include "Wire.h"
|
||||
|
||||
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
|
||||
// for both classes must be in the include path of your project
|
||||
#include "I2Cdev.h"
|
||||
|
||||
#include "MPU6050_6Axis_MotionApps20.h"
|
||||
//#include "MPU6050.h" // not necessary if using MotionApps include file
|
||||
|
||||
// class default I2C address is 0x68
|
||||
// specific I2C addresses may be passed as a parameter here
|
||||
// AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board)
|
||||
// AD0 high = 0x69
|
||||
MPU6050 mpu;
|
||||
|
||||
/* =========================================================================
|
||||
NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
|
||||
depends on the MPU-6050's INT pin being connected to the Arduino's
|
||||
external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is
|
||||
digital I/O pin 2.
|
||||
* ========================================================================= */
|
||||
|
||||
/* =========================================================================
|
||||
NOTE: Arduino v1.0.1 with the Leonardo board generates a compile error
|
||||
when using Serial.write(buf, len). The Teapot output uses this method.
|
||||
The solution requires a modification to the Arduino USBAPI.h file, which
|
||||
is fortunately simple, but annoying. This will be fixed in the next IDE
|
||||
release. For more info, see these links:
|
||||
|
||||
http://arduino.cc/forum/index.php/topic,109987.0.html
|
||||
http://code.google.com/p/arduino/issues/detail?id=958
|
||||
* ========================================================================= */
|
||||
|
||||
|
||||
|
||||
// uncomment "OUTPUT_READABLE_QUATERNION" if you want to see the actual
|
||||
// quaternion components in a [w, x, y, z] format (not best for parsing
|
||||
// on a remote host such as Processing or something though)
|
||||
//#define OUTPUT_READABLE_QUATERNION
|
||||
|
||||
// uncomment "OUTPUT_READABLE_EULER" if you want to see Euler angles
|
||||
// (in degrees) calculated from the quaternions coming from the FIFO.
|
||||
// Note that Euler angles suffer from gimbal lock (for more info, see
|
||||
// http://en.wikipedia.org/wiki/Gimbal_lock)
|
||||
//#define OUTPUT_READABLE_EULER
|
||||
|
||||
// uncomment "OUTPUT_READABLE_YAWPITCHROLL" if you want to see the yaw/
|
||||
// pitch/roll angles (in degrees) calculated from the quaternions coming
|
||||
// from the FIFO. Note this also requires gravity vector calculations.
|
||||
// Also note that yaw/pitch/roll angles suffer from gimbal lock (for
|
||||
// more info, see: http://en.wikipedia.org/wiki/Gimbal_lock)
|
||||
#define OUTPUT_READABLE_YAWPITCHROLL
|
||||
|
||||
// uncomment "OUTPUT_READABLE_REALACCEL" if you want to see acceleration
|
||||
// components with gravity removed. This acceleration reference frame is
|
||||
// not compensated for orientation, so +X is always +X according to the
|
||||
// sensor, just without the effects of gravity. If you want acceleration
|
||||
// compensated for orientation, us OUTPUT_READABLE_WORLDACCEL instead.
|
||||
//#define OUTPUT_READABLE_REALACCEL
|
||||
|
||||
// uncomment "OUTPUT_READABLE_WORLDACCEL" if you want to see acceleration
|
||||
// components with gravity removed and adjusted for the world frame of
|
||||
// reference (yaw is relative to initial orientation, since no magnetometer
|
||||
// is present in this case). Could be quite handy in some cases.
|
||||
//#define OUTPUT_READABLE_WORLDACCEL
|
||||
|
||||
// uncomment "OUTPUT_TEAPOT" if you want output that matches the
|
||||
// format used for the InvenSense teapot demo
|
||||
//#define OUTPUT_TEAPOT
|
||||
|
||||
|
||||
|
||||
#define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6)
|
||||
bool blinkState = false;
|
||||
|
||||
// MPU control/status vars
|
||||
bool dmpReady = false; // set true if DMP init was successful
|
||||
uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
|
||||
uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
|
||||
uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
|
||||
uint16_t fifoCount; // count of all bytes currently in FIFO
|
||||
uint8_t fifoBuffer[64]; // FIFO storage buffer
|
||||
|
||||
// orientation/motion vars
|
||||
Quaternion q; // [w, x, y, z] quaternion container
|
||||
VectorInt16 aa; // [x, y, z] accel sensor measurements
|
||||
VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements
|
||||
VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements
|
||||
VectorFloat gravity; // [x, y, z] gravity vector
|
||||
float euler[3]; // [psi, theta, phi] Euler angle container
|
||||
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
|
||||
|
||||
// packet structure for InvenSense teapot demo
|
||||
uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };
|
||||
|
||||
|
||||
|
||||
// ================================================================
|
||||
// === INTERRUPT DETECTION ROUTINE ===
|
||||
// ================================================================
|
||||
|
||||
volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high
|
||||
void dmpDataReady() {
|
||||
mpuInterrupt = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ================================================================
|
||||
// === INITIAL SETUP ===
|
||||
// ================================================================
|
||||
|
||||
void setup() {
|
||||
// join I2C bus (I2Cdev library doesn't do this automatically)
|
||||
Wire1.begin();
|
||||
|
||||
// initialize serial communication
|
||||
// (115200 chosen because it is required for Teapot Demo output, but it's
|
||||
// really up to you depending on your project)
|
||||
Serial.begin(115200);
|
||||
while (!Serial); // wait for Leonardo enumeration, others continue immediately
|
||||
|
||||
// NOTE: 8MHz or slower host processors, like the Teensy @ 3.3v or Ardunio
|
||||
// Pro Mini running at 3.3v, cannot handle this baud rate reliably due to
|
||||
// the baud timing being too misaligned with processor ticks. You must use
|
||||
// 38400 or slower in these cases, or use some kind of external separate
|
||||
// crystal solution for the UART timer.
|
||||
|
||||
// initialize device
|
||||
Serial.println(F("Initializing I2C devices..."));
|
||||
mpu.initialize();
|
||||
|
||||
// verify connection
|
||||
Serial.println(F("Testing device connections..."));
|
||||
Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
|
||||
|
||||
// wait for ready
|
||||
Serial.println(F("\nSend any character to begin DMP programming and demo: "));
|
||||
while (Serial.available() && Serial.read()); // empty buffer
|
||||
while (!Serial.available()); // wait for data
|
||||
while (Serial.available() && Serial.read()); // empty buffer again
|
||||
|
||||
// load and configure the DMP
|
||||
Serial.println(F("Initializing DMP..."));
|
||||
devStatus = mpu.dmpInitialize();
|
||||
|
||||
// make sure it worked (returns 0 if so)
|
||||
if (devStatus == 0) {
|
||||
// turn on the DMP, now that it's ready
|
||||
Serial.println(F("Enabling DMP..."));
|
||||
mpu.setDMPEnabled(true);
|
||||
|
||||
// enable Arduino interrupt detection
|
||||
Serial.println(F("Enabling interrupt detection (Arduino external interrupt 2)..."));
|
||||
attachInterrupt(2, dmpDataReady, RISING);
|
||||
mpuIntStatus = mpu.getIntStatus();
|
||||
|
||||
// set our DMP Ready flag so the main loop() function knows it's okay to use it
|
||||
Serial.println(F("DMP ready! Waiting for first interrupt..."));
|
||||
dmpReady = true;
|
||||
|
||||
// get expected DMP packet size for later comparison
|
||||
packetSize = mpu.dmpGetFIFOPacketSize();
|
||||
} else {
|
||||
// ERROR!
|
||||
// 1 = initial memory load failed
|
||||
// 2 = DMP configuration updates failed
|
||||
// (if it's going to break, usually the code will be 1)
|
||||
Serial.print(F("DMP Initialization failed (code "));
|
||||
Serial.print(devStatus);
|
||||
Serial.println(F(")"));
|
||||
}
|
||||
|
||||
// configure LED for output
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ================================================================
|
||||
// === MAIN PROGRAM LOOP ===
|
||||
// ================================================================
|
||||
|
||||
void loop() {
|
||||
// if programming failed, don't try to do anything
|
||||
if (!dmpReady) return;
|
||||
|
||||
// wait for MPU interrupt or extra packet(s) available
|
||||
while (!mpuInterrupt && fifoCount < packetSize) {
|
||||
// other program behavior stuff here
|
||||
// .
|
||||
// .
|
||||
// .
|
||||
// if you are really paranoid you can frequently test in between other
|
||||
// stuff to see if mpuInterrupt is true, and if so, "break;" from the
|
||||
// while() loop to immediately process the MPU data
|
||||
// .
|
||||
// .
|
||||
// .
|
||||
}
|
||||
|
||||
// reset interrupt flag and get INT_STATUS byte
|
||||
mpuInterrupt = false;
|
||||
mpuIntStatus = mpu.getIntStatus();
|
||||
|
||||
// get current FIFO count
|
||||
fifoCount = mpu.getFIFOCount();
|
||||
|
||||
// check for overflow (this should never happen unless our code is too inefficient)
|
||||
if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
|
||||
// reset so we can continue cleanly
|
||||
mpu.resetFIFO();
|
||||
Serial.println(F("FIFO overflow!"));
|
||||
|
||||
// otherwise, check for DMP data ready interrupt (this should happen frequently)
|
||||
} else if (mpuIntStatus & 0x02) {
|
||||
// wait for correct available data length, should be a VERY short wait
|
||||
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
|
||||
|
||||
// read a packet from FIFO
|
||||
mpu.getFIFOBytes(fifoBuffer, packetSize);
|
||||
|
||||
// track FIFO count here in case there is > 1 packet available
|
||||
// (this lets us immediately read more without waiting for an interrupt)
|
||||
fifoCount -= packetSize;
|
||||
|
||||
#ifdef OUTPUT_READABLE_QUATERNION
|
||||
// display quaternion values in easy matrix form: w x y z
|
||||
mpu.dmpGetQuaternion(&q, fifoBuffer);
|
||||
Serial.print("quat\t");
|
||||
Serial.print(q.w);
|
||||
Serial.print("\t");
|
||||
Serial.print(q.x);
|
||||
Serial.print("\t");
|
||||
Serial.print(q.y);
|
||||
Serial.print("\t");
|
||||
Serial.println(q.z);
|
||||
#endif
|
||||
|
||||
#ifdef OUTPUT_READABLE_EULER
|
||||
// display Euler angles in degrees
|
||||
mpu.dmpGetQuaternion(&q, fifoBuffer);
|
||||
mpu.dmpGetEuler(euler, &q);
|
||||
Serial.print("euler\t");
|
||||
Serial.print(euler[0] * 180/M_PI);
|
||||
Serial.print("\t");
|
||||
Serial.print(euler[1] * 180/M_PI);
|
||||
Serial.print("\t");
|
||||
Serial.println(euler[2] * 180/M_PI);
|
||||
#endif
|
||||
|
||||
#ifdef OUTPUT_READABLE_YAWPITCHROLL
|
||||
// display Euler angles in degrees
|
||||
mpu.dmpGetQuaternion(&q, fifoBuffer);
|
||||
mpu.dmpGetGravity(&gravity, &q);
|
||||
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
|
||||
Serial.print("ypr\t");
|
||||
Serial.print(ypr[0] * 180/M_PI);
|
||||
Serial.print("\t");
|
||||
Serial.print(ypr[1] * 180/M_PI);
|
||||
Serial.print("\t");
|
||||
Serial.println(ypr[2] * 180/M_PI);
|
||||
#endif
|
||||
|
||||
#ifdef OUTPUT_READABLE_REALACCEL
|
||||
// display real acceleration, adjusted to remove gravity
|
||||
mpu.dmpGetQuaternion(&q, fifoBuffer);
|
||||
mpu.dmpGetAccel(&aa, fifoBuffer);
|
||||
mpu.dmpGetGravity(&gravity, &q);
|
||||
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
|
||||
Serial.print("areal\t");
|
||||
Serial.print(aaReal.x);
|
||||
Serial.print("\t");
|
||||
Serial.print(aaReal.y);
|
||||
Serial.print("\t");
|
||||
Serial.println(aaReal.z);
|
||||
#endif
|
||||
|
||||
#ifdef OUTPUT_READABLE_WORLDACCEL
|
||||
// display initial world-frame acceleration, adjusted to remove gravity
|
||||
// and rotated based on known orientation from quaternion
|
||||
mpu.dmpGetQuaternion(&q, fifoBuffer);
|
||||
mpu.dmpGetAccel(&aa, fifoBuffer);
|
||||
mpu.dmpGetGravity(&gravity, &q);
|
||||
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
|
||||
mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
|
||||
Serial.print("aworld\t");
|
||||
Serial.print(aaWorld.x);
|
||||
Serial.print("\t");
|
||||
Serial.print(aaWorld.y);
|
||||
Serial.print("\t");
|
||||
Serial.println(aaWorld.z);
|
||||
#endif
|
||||
|
||||
#ifdef OUTPUT_TEAPOT
|
||||
// display quaternion values in InvenSense Teapot demo format:
|
||||
teapotPacket[2] = fifoBuffer[0];
|
||||
teapotPacket[3] = fifoBuffer[1];
|
||||
teapotPacket[4] = fifoBuffer[4];
|
||||
teapotPacket[5] = fifoBuffer[5];
|
||||
teapotPacket[6] = fifoBuffer[8];
|
||||
teapotPacket[7] = fifoBuffer[9];
|
||||
teapotPacket[8] = fifoBuffer[12];
|
||||
teapotPacket[9] = fifoBuffer[13];
|
||||
Serial.write(teapotPacket, 14);
|
||||
teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
|
||||
#endif
|
||||
|
||||
// blink LED to indicate activity
|
||||
blinkState = !blinkState;
|
||||
digitalWrite(LED_PIN, blinkState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
// I2C device class (I2Cdev) demonstration Processing sketch for MPU6050 DMP output
|
||||
// 6/20/2012 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// 2012-06-20 - initial release
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
import processing.serial.*;
|
||||
import processing.opengl.*;
|
||||
import toxi.geom.*;
|
||||
import toxi.processing.*;
|
||||
|
||||
// NOTE: requires ToxicLibs to be installed in order to run properly.
|
||||
// 1. Download from http://toxiclibs.org/downloads
|
||||
// 2. Extract into [userdir]/Processing/libraries
|
||||
// (location may be different on Mac/Linux)
|
||||
// 3. Run and bask in awesomeness
|
||||
|
||||
ToxiclibsSupport gfx;
|
||||
|
||||
Serial port; // The serial port
|
||||
char[] teapotPacket = new char[14]; // InvenSense Teapot packet
|
||||
int serialCount = 0; // current packet byte position
|
||||
int aligned = 0;
|
||||
int interval = 0;
|
||||
|
||||
float[] q = new float[4];
|
||||
Quaternion quat = new Quaternion(1, 0, 0, 0);
|
||||
|
||||
float[] gravity = new float[3];
|
||||
float[] euler = new float[3];
|
||||
float[] ypr = new float[3];
|
||||
|
||||
void setup() {
|
||||
// 300px square viewport using OpenGL rendering
|
||||
size(300, 300, OPENGL);
|
||||
gfx = new ToxiclibsSupport(this);
|
||||
|
||||
// setup lights and antialiasing
|
||||
lights();
|
||||
smooth();
|
||||
|
||||
// display serial port list for debugging/clarity
|
||||
println(Serial.list());
|
||||
|
||||
// get the first available port (use EITHER this OR the specific port code below)
|
||||
String portName = Serial.list()[0];
|
||||
|
||||
// get a specific serial port (use EITHER this OR the first-available code above)
|
||||
//String portName = "COM4";
|
||||
|
||||
// open the serial port
|
||||
port = new Serial(this, portName, 115200);
|
||||
|
||||
// send single character to trigger DMP init/start
|
||||
// (expected by MPU6050_DMP6 example Arduino sketch)
|
||||
port.write('r');
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if (millis() - interval > 1000) {
|
||||
// resend single character to trigger DMP init/start
|
||||
// in case the MPU is halted/reset while applet is running
|
||||
port.write('r');
|
||||
interval = millis();
|
||||
}
|
||||
|
||||
// black background
|
||||
background(0);
|
||||
|
||||
// translate everything to the middle of the viewport
|
||||
pushMatrix();
|
||||
translate(width / 2, height / 2);
|
||||
|
||||
// 3-step rotation from yaw/pitch/roll angles (gimbal lock!)
|
||||
// ...and other weirdness I haven't figured out yet
|
||||
//rotateY(-ypr[0]);
|
||||
//rotateZ(-ypr[1]);
|
||||
//rotateX(-ypr[2]);
|
||||
|
||||
// toxiclibs direct angle/axis rotation from quaternion (NO gimbal lock!)
|
||||
// (axis order [1, 3, 2] and inversion [-1, +1, +1] is a consequence of
|
||||
// different coordinate system orientation assumptions between Processing
|
||||
// and InvenSense DMP)
|
||||
float[] axis = quat.toAxisAngle();
|
||||
rotate(axis[0], -axis[1], axis[3], axis[2]);
|
||||
|
||||
// draw main body in red
|
||||
fill(255, 0, 0, 200);
|
||||
box(10, 10, 200);
|
||||
|
||||
// draw front-facing tip in blue
|
||||
fill(0, 0, 255, 200);
|
||||
pushMatrix();
|
||||
translate(0, 0, -120);
|
||||
rotateX(PI/2);
|
||||
drawCylinder(0, 20, 20, 8);
|
||||
popMatrix();
|
||||
|
||||
// draw wings and tail fin in green
|
||||
fill(0, 255, 0, 200);
|
||||
beginShape(TRIANGLES);
|
||||
vertex(-100, 2, 30); vertex(0, 2, -80); vertex(100, 2, 30); // wing top layer
|
||||
vertex(-100, -2, 30); vertex(0, -2, -80); vertex(100, -2, 30); // wing bottom layer
|
||||
vertex(-2, 0, 98); vertex(-2, -30, 98); vertex(-2, 0, 70); // tail left layer
|
||||
vertex( 2, 0, 98); vertex( 2, -30, 98); vertex( 2, 0, 70); // tail right layer
|
||||
endShape();
|
||||
beginShape(QUADS);
|
||||
vertex(-100, 2, 30); vertex(-100, -2, 30); vertex( 0, -2, -80); vertex( 0, 2, -80);
|
||||
vertex( 100, 2, 30); vertex( 100, -2, 30); vertex( 0, -2, -80); vertex( 0, 2, -80);
|
||||
vertex(-100, 2, 30); vertex(-100, -2, 30); vertex(100, -2, 30); vertex(100, 2, 30);
|
||||
vertex(-2, 0, 98); vertex(2, 0, 98); vertex(2, -30, 98); vertex(-2, -30, 98);
|
||||
vertex(-2, 0, 98); vertex(2, 0, 98); vertex(2, 0, 70); vertex(-2, 0, 70);
|
||||
vertex(-2, -30, 98); vertex(2, -30, 98); vertex(2, 0, 70); vertex(-2, 0, 70);
|
||||
endShape();
|
||||
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void serialEvent(Serial port) {
|
||||
interval = millis();
|
||||
while (port.available() > 0) {
|
||||
int ch = port.read();
|
||||
print((char)ch);
|
||||
if (aligned < 4) {
|
||||
// make sure we are properly aligned on a 14-byte packet
|
||||
if (serialCount == 0) {
|
||||
if (ch == '$') aligned++; else aligned = 0;
|
||||
} else if (serialCount == 1) {
|
||||
if (ch == 2) aligned++; else aligned = 0;
|
||||
} else if (serialCount == 12) {
|
||||
if (ch == '\r') aligned++; else aligned = 0;
|
||||
} else if (serialCount == 13) {
|
||||
if (ch == '\n') aligned++; else aligned = 0;
|
||||
}
|
||||
//println(ch + " " + aligned + " " + serialCount);
|
||||
serialCount++;
|
||||
if (serialCount == 14) serialCount = 0;
|
||||
} else {
|
||||
if (serialCount > 0 || ch == '$') {
|
||||
teapotPacket[serialCount++] = (char)ch;
|
||||
if (serialCount == 14) {
|
||||
serialCount = 0; // restart packet byte position
|
||||
|
||||
// get quaternion from data packet
|
||||
q[0] = ((teapotPacket[2] << 8) | teapotPacket[3]) / 16384.0f;
|
||||
q[1] = ((teapotPacket[4] << 8) | teapotPacket[5]) / 16384.0f;
|
||||
q[2] = ((teapotPacket[6] << 8) | teapotPacket[7]) / 16384.0f;
|
||||
q[3] = ((teapotPacket[8] << 8) | teapotPacket[9]) / 16384.0f;
|
||||
for (int i = 0; i < 4; i++) if (q[i] >= 2) q[i] = -4 + q[i];
|
||||
|
||||
// set our toxilibs quaternion to new data
|
||||
quat.set(q[0], q[1], q[2], q[3]);
|
||||
|
||||
/*
|
||||
// below calculations unnecessary for orientation only using toxilibs
|
||||
|
||||
// calculate gravity vector
|
||||
gravity[0] = 2 * (q[1]*q[3] - q[0]*q[2]);
|
||||
gravity[1] = 2 * (q[0]*q[1] + q[2]*q[3]);
|
||||
gravity[2] = q[0]*q[0] - q[1]*q[1] - q[2]*q[2] + q[3]*q[3];
|
||||
|
||||
// calculate Euler angles
|
||||
euler[0] = atan2(2*q[1]*q[2] - 2*q[0]*q[3], 2*q[0]*q[0] + 2*q[1]*q[1] - 1);
|
||||
euler[1] = -asin(2*q[1]*q[3] + 2*q[0]*q[2]);
|
||||
euler[2] = atan2(2*q[2]*q[3] - 2*q[0]*q[1], 2*q[0]*q[0] + 2*q[3]*q[3] - 1);
|
||||
|
||||
// calculate yaw/pitch/roll angles
|
||||
ypr[0] = atan2(2*q[1]*q[2] - 2*q[0]*q[3], 2*q[0]*q[0] + 2*q[1]*q[1] - 1);
|
||||
ypr[1] = atan(gravity[0] / sqrt(gravity[1]*gravity[1] + gravity[2]*gravity[2]));
|
||||
ypr[2] = atan(gravity[1] / sqrt(gravity[0]*gravity[0] + gravity[2]*gravity[2]));
|
||||
|
||||
// output various components for debugging
|
||||
//println("q:\t" + round(q[0]*100.0f)/100.0f + "\t" + round(q[1]*100.0f)/100.0f + "\t" + round(q[2]*100.0f)/100.0f + "\t" + round(q[3]*100.0f)/100.0f);
|
||||
//println("euler:\t" + euler[0]*180.0f/PI + "\t" + euler[1]*180.0f/PI + "\t" + euler[2]*180.0f/PI);
|
||||
//println("ypr:\t" + ypr[0]*180.0f/PI + "\t" + ypr[1]*180.0f/PI + "\t" + ypr[2]*180.0f/PI);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
|
||||
float angle = 0;
|
||||
float angleIncrement = TWO_PI / sides;
|
||||
beginShape(QUAD_STRIP);
|
||||
for (int i = 0; i < sides + 1; ++i) {
|
||||
vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
|
||||
vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
|
||||
// If it is not a cone, draw the circular top cap
|
||||
if (topRadius != 0) {
|
||||
angle = 0;
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
// Center point
|
||||
vertex(0, 0, 0);
|
||||
for (int i = 0; i < sides + 1; i++) {
|
||||
vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
|
||||
// If it is not a cone, draw the circular bottom cap
|
||||
if (bottomRadius != 0) {
|
||||
angle = 0;
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
// Center point
|
||||
vertex(0, tall, 0);
|
||||
for (int i = 0; i < sides + 1; i++) {
|
||||
vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
|
||||
// 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// 2011-10-07 - initial release
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2011 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
|
||||
// is used in I2Cdev.h
|
||||
#include "Wire.h"
|
||||
|
||||
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
|
||||
// for both classes must be in the include path of your project
|
||||
#include "I2Cdev.h"
|
||||
#include "MPU6050.h"
|
||||
|
||||
// class default I2C address is 0x68
|
||||
// specific I2C addresses may be passed as a parameter here
|
||||
// AD0 low = 0x68 (default for InvenSense evaluation board)
|
||||
// AD0 high = 0x69
|
||||
MPU6050 accelgyro;
|
||||
|
||||
int16_t ax, ay, az;
|
||||
int16_t gx, gy, gz;
|
||||
|
||||
#define LED_PIN 13
|
||||
bool blinkState = false;
|
||||
|
||||
void setup() {
|
||||
// join I2C bus (I2Cdev library doesn't do this automatically)
|
||||
Wire1.begin();
|
||||
|
||||
// initialize serial communication
|
||||
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
|
||||
// it's really up to you depending on your project)
|
||||
SerialUSB.begin(9600);
|
||||
|
||||
// initialize device
|
||||
SerialUSB.println("Initializing I2C devices...");
|
||||
accelgyro.initialize();
|
||||
|
||||
// verify connection
|
||||
SerialUSB.println("Testing device connections...");
|
||||
SerialUSB.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
|
||||
|
||||
// configure Arduino LED for
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read raw accel/gyro measurements from device
|
||||
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
|
||||
|
||||
// these methods (and a few others) are also available
|
||||
//accelgyro.getAcceleration(&ax, &ay, &az);
|
||||
//accelgyro.getRotation(&gx, &gy, &gz);
|
||||
|
||||
// display tab-separated accel/gyro x/y/z values
|
||||
SerialUSB.print("a/g:\t");
|
||||
SerialUSB.print(ax); SerialUSB.print("\t");
|
||||
SerialUSB.print(ay); SerialUSB.print("\t");
|
||||
SerialUSB.print(az); SerialUSB.print("\t");
|
||||
SerialUSB.print(gx); SerialUSB.print("\t");
|
||||
SerialUSB.print(gy); SerialUSB.print("\t");
|
||||
SerialUSB.println(gz);
|
||||
|
||||
// blink LED to indicate activity
|
||||
blinkState = !blinkState;
|
||||
digitalWrite(LED_PIN, blinkState);
|
||||
delay(500);
|
||||
}
|
||||
3142
digistump-sam/libraries/MPU6050/MPU6050.cpp
Normal file
3142
digistump-sam/libraries/MPU6050/MPU6050.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1024
digistump-sam/libraries/MPU6050/MPU6050.h
Normal file
1024
digistump-sam/libraries/MPU6050/MPU6050.h
Normal file
File diff suppressed because it is too large
Load Diff
697
digistump-sam/libraries/MPU6050/MPU6050_6Axis_MotionApps20.h
Normal file
697
digistump-sam/libraries/MPU6050/MPU6050_6Axis_MotionApps20.h
Normal file
@@ -0,0 +1,697 @@
|
||||
// I2Cdev library collection - MPU6050 I2C device class, 6-axis MotionApps 2.0 implementation
|
||||
// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
||||
// 5/20/2013 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// ... - ongoing debug release
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
#ifndef _MPU6050_6AXIS_MOTIONAPPS20_H_
|
||||
#define _MPU6050_6AXIS_MOTIONAPPS20_H_
|
||||
|
||||
#include "I2Cdev.h"
|
||||
#include "helper_3dmath.h"
|
||||
|
||||
// MotionApps 2.0 DMP implementation, built using the MPU-6050EVB evaluation board
|
||||
#define MPU6050_INCLUDE_DMP_MOTIONAPPS20
|
||||
|
||||
#include "MPU6050.h"
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
/* Source is from the InvenSense MotionApps v2 demo code. Original source is
|
||||
* unavailable, unless you happen to be amazing as decompiling binary by
|
||||
* hand (in which case, please contact me, and I'm totally serious).
|
||||
*
|
||||
* Also, I'd like to offer many, many thanks to Noah Zerkin for all of the
|
||||
* DMP reverse-engineering he did to help make this bit of wizardry
|
||||
* possible.
|
||||
*/
|
||||
|
||||
// NOTE! Enabling DEBUG adds about 3.3kB to the flash program size.
|
||||
// Debug output is now working even on ATMega328P MCUs (e.g. Arduino Uno)
|
||||
// after moving string constants to flash memory storage using the F()
|
||||
// compiler macro (Arduino IDE 1.0+ required).
|
||||
|
||||
//#define DEBUG
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINT(x) Serial.print(x)
|
||||
#define DEBUG_PRINTF(x, y) Serial.print(x, y)
|
||||
#define DEBUG_PRINTLN(x) Serial.println(x)
|
||||
#define DEBUG_PRINTLNF(x, y) Serial.println(x, y)
|
||||
#else
|
||||
#define DEBUG_PRINT(x)
|
||||
#define DEBUG_PRINTF(x, y)
|
||||
#define DEBUG_PRINTLN(x)
|
||||
#define DEBUG_PRINTLNF(x, y)
|
||||
#endif
|
||||
|
||||
#define MPU6050_DMP_CODE_SIZE 1929 // dmpMemory[]
|
||||
#define MPU6050_DMP_CONFIG_SIZE 192 // dmpConfig[]
|
||||
#define MPU6050_DMP_UPDATES_SIZE 47 // dmpUpdates[]
|
||||
|
||||
/* ================================================================================================ *
|
||||
| Default MotionApps v2.0 42-byte FIFO packet structure: |
|
||||
| |
|
||||
| [QUAT W][ ][QUAT X][ ][QUAT Y][ ][QUAT Z][ ][GYRO X][ ][GYRO Y][ ] |
|
||||
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
||||
| |
|
||||
| [GYRO Z][ ][ACC X ][ ][ACC Y ][ ][ACC Z ][ ][ ] |
|
||||
| 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
||||
* ================================================================================================ */
|
||||
|
||||
// this block of memory gets written to the MPU on start-up, and it seems
|
||||
// to be volatile memory, so it has to be done each time (it only takes ~1
|
||||
// second though)
|
||||
const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = {
|
||||
// bank 0, 256 bytes
|
||||
0xFB, 0x00, 0x00, 0x3E, 0x00, 0x0B, 0x00, 0x36, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
|
||||
0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01,
|
||||
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x03, 0xE8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFE, 0x80, 0x01,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x3E, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCA, 0xE3, 0x09, 0x3E, 0x80, 0x00, 0x00,
|
||||
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
|
||||
0x41, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x2A, 0x00, 0x00, 0x16, 0x55, 0x00, 0x00, 0x21, 0x82,
|
||||
0xFD, 0x87, 0x26, 0x50, 0xFD, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x80, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x02, 0x65, 0x32, 0x00, 0x00, 0x5E, 0xC0,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFB, 0x8C, 0x6F, 0x5D, 0xFD, 0x5D, 0x08, 0xD9, 0x00, 0x7C, 0x73, 0x3B, 0x00, 0x6C, 0x12, 0xCC,
|
||||
0x32, 0x00, 0x13, 0x9D, 0x32, 0x00, 0xD0, 0xD6, 0x32, 0x00, 0x08, 0x00, 0x40, 0x00, 0x01, 0xF4,
|
||||
0xFF, 0xE6, 0x80, 0x79, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xD6, 0x00, 0x00, 0x27, 0x10,
|
||||
|
||||
// bank 1, 256 bytes
|
||||
0xFB, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFA, 0x36, 0xFF, 0xBC, 0x30, 0x8E, 0x00, 0x05, 0xFB, 0xF0, 0xFF, 0xD9, 0x5B, 0xC8,
|
||||
0xFF, 0xD0, 0x9A, 0xBE, 0x00, 0x00, 0x10, 0xA9, 0xFF, 0xF4, 0x1E, 0xB2, 0x00, 0xCE, 0xBB, 0xF7,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x0C,
|
||||
0xFF, 0xC2, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xCF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x68, 0xB6, 0x79, 0x35, 0x28, 0xBC, 0xC6, 0x7E, 0xD1, 0x6C,
|
||||
0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x30,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x25, 0x4D, 0x00, 0x2F, 0x70, 0x6D, 0x00, 0x00, 0x05, 0xAE, 0x00, 0x0C, 0x02, 0xD0,
|
||||
|
||||
// bank 2, 256 bytes
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0xFF, 0xEF, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
// bank 3, 256 bytes
|
||||
0xD8, 0xDC, 0xBA, 0xA2, 0xF1, 0xDE, 0xB2, 0xB8, 0xB4, 0xA8, 0x81, 0x91, 0xF7, 0x4A, 0x90, 0x7F,
|
||||
0x91, 0x6A, 0xF3, 0xF9, 0xDB, 0xA8, 0xF9, 0xB0, 0xBA, 0xA0, 0x80, 0xF2, 0xCE, 0x81, 0xF3, 0xC2,
|
||||
0xF1, 0xC1, 0xF2, 0xC3, 0xF3, 0xCC, 0xA2, 0xB2, 0x80, 0xF1, 0xC6, 0xD8, 0x80, 0xBA, 0xA7, 0xDF,
|
||||
0xDF, 0xDF, 0xF2, 0xA7, 0xC3, 0xCB, 0xC5, 0xB6, 0xF0, 0x87, 0xA2, 0x94, 0x24, 0x48, 0x70, 0x3C,
|
||||
0x95, 0x40, 0x68, 0x34, 0x58, 0x9B, 0x78, 0xA2, 0xF1, 0x83, 0x92, 0x2D, 0x55, 0x7D, 0xD8, 0xB1,
|
||||
0xB4, 0xB8, 0xA1, 0xD0, 0x91, 0x80, 0xF2, 0x70, 0xF3, 0x70, 0xF2, 0x7C, 0x80, 0xA8, 0xF1, 0x01,
|
||||
0xB0, 0x98, 0x87, 0xD9, 0x43, 0xD8, 0x86, 0xC9, 0x88, 0xBA, 0xA1, 0xF2, 0x0E, 0xB8, 0x97, 0x80,
|
||||
0xF1, 0xA9, 0xDF, 0xDF, 0xDF, 0xAA, 0xDF, 0xDF, 0xDF, 0xF2, 0xAA, 0xC5, 0xCD, 0xC7, 0xA9, 0x0C,
|
||||
0xC9, 0x2C, 0x97, 0x97, 0x97, 0x97, 0xF1, 0xA9, 0x89, 0x26, 0x46, 0x66, 0xB0, 0xB4, 0xBA, 0x80,
|
||||
0xAC, 0xDE, 0xF2, 0xCA, 0xF1, 0xB2, 0x8C, 0x02, 0xA9, 0xB6, 0x98, 0x00, 0x89, 0x0E, 0x16, 0x1E,
|
||||
0xB8, 0xA9, 0xB4, 0x99, 0x2C, 0x54, 0x7C, 0xB0, 0x8A, 0xA8, 0x96, 0x36, 0x56, 0x76, 0xF1, 0xB9,
|
||||
0xAF, 0xB4, 0xB0, 0x83, 0xC0, 0xB8, 0xA8, 0x97, 0x11, 0xB1, 0x8F, 0x98, 0xB9, 0xAF, 0xF0, 0x24,
|
||||
0x08, 0x44, 0x10, 0x64, 0x18, 0xF1, 0xA3, 0x29, 0x55, 0x7D, 0xAF, 0x83, 0xB5, 0x93, 0xAF, 0xF0,
|
||||
0x00, 0x28, 0x50, 0xF1, 0xA3, 0x86, 0x9F, 0x61, 0xA6, 0xDA, 0xDE, 0xDF, 0xD9, 0xFA, 0xA3, 0x86,
|
||||
0x96, 0xDB, 0x31, 0xA6, 0xD9, 0xF8, 0xDF, 0xBA, 0xA6, 0x8F, 0xC2, 0xC5, 0xC7, 0xB2, 0x8C, 0xC1,
|
||||
0xB8, 0xA2, 0xDF, 0xDF, 0xDF, 0xA3, 0xDF, 0xDF, 0xDF, 0xD8, 0xD8, 0xF1, 0xB8, 0xA8, 0xB2, 0x86,
|
||||
|
||||
// bank 4, 256 bytes
|
||||
0xB4, 0x98, 0x0D, 0x35, 0x5D, 0xB8, 0xAA, 0x98, 0xB0, 0x87, 0x2D, 0x35, 0x3D, 0xB2, 0xB6, 0xBA,
|
||||
0xAF, 0x8C, 0x96, 0x19, 0x8F, 0x9F, 0xA7, 0x0E, 0x16, 0x1E, 0xB4, 0x9A, 0xB8, 0xAA, 0x87, 0x2C,
|
||||
0x54, 0x7C, 0xB9, 0xA3, 0xDE, 0xDF, 0xDF, 0xA3, 0xB1, 0x80, 0xF2, 0xC4, 0xCD, 0xC9, 0xF1, 0xB8,
|
||||
0xA9, 0xB4, 0x99, 0x83, 0x0D, 0x35, 0x5D, 0x89, 0xB9, 0xA3, 0x2D, 0x55, 0x7D, 0xB5, 0x93, 0xA3,
|
||||
0x0E, 0x16, 0x1E, 0xA9, 0x2C, 0x54, 0x7C, 0xB8, 0xB4, 0xB0, 0xF1, 0x97, 0x83, 0xA8, 0x11, 0x84,
|
||||
0xA5, 0x09, 0x98, 0xA3, 0x83, 0xF0, 0xDA, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0xD8, 0xF1, 0xA5,
|
||||
0x29, 0x55, 0x7D, 0xA5, 0x85, 0x95, 0x02, 0x1A, 0x2E, 0x3A, 0x56, 0x5A, 0x40, 0x48, 0xF9, 0xF3,
|
||||
0xA3, 0xD9, 0xF8, 0xF0, 0x98, 0x83, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0x97, 0x82, 0xA8, 0xF1,
|
||||
0x11, 0xF0, 0x98, 0xA2, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0xDA, 0xF3, 0xDE, 0xD8, 0x83, 0xA5,
|
||||
0x94, 0x01, 0xD9, 0xA3, 0x02, 0xF1, 0xA2, 0xC3, 0xC5, 0xC7, 0xD8, 0xF1, 0x84, 0x92, 0xA2, 0x4D,
|
||||
0xDA, 0x2A, 0xD8, 0x48, 0x69, 0xD9, 0x2A, 0xD8, 0x68, 0x55, 0xDA, 0x32, 0xD8, 0x50, 0x71, 0xD9,
|
||||
0x32, 0xD8, 0x70, 0x5D, 0xDA, 0x3A, 0xD8, 0x58, 0x79, 0xD9, 0x3A, 0xD8, 0x78, 0x93, 0xA3, 0x4D,
|
||||
0xDA, 0x2A, 0xD8, 0x48, 0x69, 0xD9, 0x2A, 0xD8, 0x68, 0x55, 0xDA, 0x32, 0xD8, 0x50, 0x71, 0xD9,
|
||||
0x32, 0xD8, 0x70, 0x5D, 0xDA, 0x3A, 0xD8, 0x58, 0x79, 0xD9, 0x3A, 0xD8, 0x78, 0xA8, 0x8A, 0x9A,
|
||||
0xF0, 0x28, 0x50, 0x78, 0x9E, 0xF3, 0x88, 0x18, 0xF1, 0x9F, 0x1D, 0x98, 0xA8, 0xD9, 0x08, 0xD8,
|
||||
0xC8, 0x9F, 0x12, 0x9E, 0xF3, 0x15, 0xA8, 0xDA, 0x12, 0x10, 0xD8, 0xF1, 0xAF, 0xC8, 0x97, 0x87,
|
||||
|
||||
// bank 5, 256 bytes
|
||||
0x34, 0xB5, 0xB9, 0x94, 0xA4, 0x21, 0xF3, 0xD9, 0x22, 0xD8, 0xF2, 0x2D, 0xF3, 0xD9, 0x2A, 0xD8,
|
||||
0xF2, 0x35, 0xF3, 0xD9, 0x32, 0xD8, 0x81, 0xA4, 0x60, 0x60, 0x61, 0xD9, 0x61, 0xD8, 0x6C, 0x68,
|
||||
0x69, 0xD9, 0x69, 0xD8, 0x74, 0x70, 0x71, 0xD9, 0x71, 0xD8, 0xB1, 0xA3, 0x84, 0x19, 0x3D, 0x5D,
|
||||
0xA3, 0x83, 0x1A, 0x3E, 0x5E, 0x93, 0x10, 0x30, 0x81, 0x10, 0x11, 0xB8, 0xB0, 0xAF, 0x8F, 0x94,
|
||||
0xF2, 0xDA, 0x3E, 0xD8, 0xB4, 0x9A, 0xA8, 0x87, 0x29, 0xDA, 0xF8, 0xD8, 0x87, 0x9A, 0x35, 0xDA,
|
||||
0xF8, 0xD8, 0x87, 0x9A, 0x3D, 0xDA, 0xF8, 0xD8, 0xB1, 0xB9, 0xA4, 0x98, 0x85, 0x02, 0x2E, 0x56,
|
||||
0xA5, 0x81, 0x00, 0x0C, 0x14, 0xA3, 0x97, 0xB0, 0x8A, 0xF1, 0x2D, 0xD9, 0x28, 0xD8, 0x4D, 0xD9,
|
||||
0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0xB1, 0x84, 0x0D, 0xDA, 0x0E, 0xD8, 0xA3, 0x29, 0x83, 0xDA,
|
||||
0x2C, 0x0E, 0xD8, 0xA3, 0x84, 0x49, 0x83, 0xDA, 0x2C, 0x4C, 0x0E, 0xD8, 0xB8, 0xB0, 0xA8, 0x8A,
|
||||
0x9A, 0xF5, 0x20, 0xAA, 0xDA, 0xDF, 0xD8, 0xA8, 0x40, 0xAA, 0xD0, 0xDA, 0xDE, 0xD8, 0xA8, 0x60,
|
||||
0xAA, 0xDA, 0xD0, 0xDF, 0xD8, 0xF1, 0x97, 0x86, 0xA8, 0x31, 0x9B, 0x06, 0x99, 0x07, 0xAB, 0x97,
|
||||
0x28, 0x88, 0x9B, 0xF0, 0x0C, 0x20, 0x14, 0x40, 0xB8, 0xB0, 0xB4, 0xA8, 0x8C, 0x9C, 0xF0, 0x04,
|
||||
0x28, 0x51, 0x79, 0x1D, 0x30, 0x14, 0x38, 0xB2, 0x82, 0xAB, 0xD0, 0x98, 0x2C, 0x50, 0x50, 0x78,
|
||||
0x78, 0x9B, 0xF1, 0x1A, 0xB0, 0xF0, 0x8A, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x8B, 0x29, 0x51, 0x79,
|
||||
0x8A, 0x24, 0x70, 0x59, 0x8B, 0x20, 0x58, 0x71, 0x8A, 0x44, 0x69, 0x38, 0x8B, 0x39, 0x40, 0x68,
|
||||
0x8A, 0x64, 0x48, 0x31, 0x8B, 0x30, 0x49, 0x60, 0xA5, 0x88, 0x20, 0x09, 0x71, 0x58, 0x44, 0x68,
|
||||
|
||||
// bank 6, 256 bytes
|
||||
0x11, 0x39, 0x64, 0x49, 0x30, 0x19, 0xF1, 0xAC, 0x00, 0x2C, 0x54, 0x7C, 0xF0, 0x8C, 0xA8, 0x04,
|
||||
0x28, 0x50, 0x78, 0xF1, 0x88, 0x97, 0x26, 0xA8, 0x59, 0x98, 0xAC, 0x8C, 0x02, 0x26, 0x46, 0x66,
|
||||
0xF0, 0x89, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38, 0x64, 0x48, 0x31,
|
||||
0xA9, 0x88, 0x09, 0x20, 0x59, 0x70, 0xAB, 0x11, 0x38, 0x40, 0x69, 0xA8, 0x19, 0x31, 0x48, 0x60,
|
||||
0x8C, 0xA8, 0x3C, 0x41, 0x5C, 0x20, 0x7C, 0x00, 0xF1, 0x87, 0x98, 0x19, 0x86, 0xA8, 0x6E, 0x76,
|
||||
0x7E, 0xA9, 0x99, 0x88, 0x2D, 0x55, 0x7D, 0x9E, 0xB9, 0xA3, 0x8A, 0x22, 0x8A, 0x6E, 0x8A, 0x56,
|
||||
0x8A, 0x5E, 0x9F, 0xB1, 0x83, 0x06, 0x26, 0x46, 0x66, 0x0E, 0x2E, 0x4E, 0x6E, 0x9D, 0xB8, 0xAD,
|
||||
0x00, 0x2C, 0x54, 0x7C, 0xF2, 0xB1, 0x8C, 0xB4, 0x99, 0xB9, 0xA3, 0x2D, 0x55, 0x7D, 0x81, 0x91,
|
||||
0xAC, 0x38, 0xAD, 0x3A, 0xB5, 0x83, 0x91, 0xAC, 0x2D, 0xD9, 0x28, 0xD8, 0x4D, 0xD9, 0x48, 0xD8,
|
||||
0x6D, 0xD9, 0x68, 0xD8, 0x8C, 0x9D, 0xAE, 0x29, 0xD9, 0x04, 0xAE, 0xD8, 0x51, 0xD9, 0x04, 0xAE,
|
||||
0xD8, 0x79, 0xD9, 0x04, 0xD8, 0x81, 0xF3, 0x9D, 0xAD, 0x00, 0x8D, 0xAE, 0x19, 0x81, 0xAD, 0xD9,
|
||||
0x01, 0xD8, 0xF2, 0xAE, 0xDA, 0x26, 0xD8, 0x8E, 0x91, 0x29, 0x83, 0xA7, 0xD9, 0xAD, 0xAD, 0xAD,
|
||||
0xAD, 0xF3, 0x2A, 0xD8, 0xD8, 0xF1, 0xB0, 0xAC, 0x89, 0x91, 0x3E, 0x5E, 0x76, 0xF3, 0xAC, 0x2E,
|
||||
0x2E, 0xF1, 0xB1, 0x8C, 0x5A, 0x9C, 0xAC, 0x2C, 0x28, 0x28, 0x28, 0x9C, 0xAC, 0x30, 0x18, 0xA8,
|
||||
0x98, 0x81, 0x28, 0x34, 0x3C, 0x97, 0x24, 0xA7, 0x28, 0x34, 0x3C, 0x9C, 0x24, 0xF2, 0xB0, 0x89,
|
||||
0xAC, 0x91, 0x2C, 0x4C, 0x6C, 0x8A, 0x9B, 0x2D, 0xD9, 0xD8, 0xD8, 0x51, 0xD9, 0xD8, 0xD8, 0x79,
|
||||
|
||||
// bank 7, 138 bytes (remainder)
|
||||
0xD9, 0xD8, 0xD8, 0xF1, 0x9E, 0x88, 0xA3, 0x31, 0xDA, 0xD8, 0xD8, 0x91, 0x2D, 0xD9, 0x28, 0xD8,
|
||||
0x4D, 0xD9, 0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0xB1, 0x83, 0x93, 0x35, 0x3D, 0x80, 0x25, 0xDA,
|
||||
0xD8, 0xD8, 0x85, 0x69, 0xDA, 0xD8, 0xD8, 0xB4, 0x93, 0x81, 0xA3, 0x28, 0x34, 0x3C, 0xF3, 0xAB,
|
||||
0x8B, 0xF8, 0xA3, 0x91, 0xB6, 0x09, 0xB4, 0xD9, 0xAB, 0xDE, 0xFA, 0xB0, 0x87, 0x9C, 0xB9, 0xA3,
|
||||
0xDD, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x95, 0xF1, 0xA3, 0xA3, 0xA3, 0x9D, 0xF1, 0xA3, 0xA3, 0xA3,
|
||||
0xA3, 0xF2, 0xA3, 0xB4, 0x90, 0x80, 0xF2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3,
|
||||
0xA3, 0xB2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xB0, 0x87, 0xB5, 0x99, 0xF1, 0xA3, 0xA3, 0xA3,
|
||||
0x98, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x97, 0xA3, 0xA3, 0xA3, 0xA3, 0xF3, 0x9B, 0xA3, 0xA3, 0xDC,
|
||||
0xB9, 0xA7, 0xF1, 0x26, 0x26, 0x26, 0xD8, 0xD8, 0xFF
|
||||
};
|
||||
|
||||
// thanks to Noah Zerkin for piecing this stuff together!
|
||||
const unsigned char dmpConfig[MPU6050_DMP_CONFIG_SIZE] PROGMEM = {
|
||||
// BANK OFFSET LENGTH [DATA]
|
||||
0x03, 0x7B, 0x03, 0x4C, 0xCD, 0x6C, // FCFG_1 inv_set_gyro_calibration
|
||||
0x03, 0xAB, 0x03, 0x36, 0x56, 0x76, // FCFG_3 inv_set_gyro_calibration
|
||||
0x00, 0x68, 0x04, 0x02, 0xCB, 0x47, 0xA2, // D_0_104 inv_set_gyro_calibration
|
||||
0x02, 0x18, 0x04, 0x00, 0x05, 0x8B, 0xC1, // D_0_24 inv_set_gyro_calibration
|
||||
0x01, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // D_1_152 inv_set_accel_calibration
|
||||
0x03, 0x7F, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, // FCFG_2 inv_set_accel_calibration
|
||||
0x03, 0x89, 0x03, 0x26, 0x46, 0x66, // FCFG_7 inv_set_accel_calibration
|
||||
0x00, 0x6C, 0x02, 0x20, 0x00, // D_0_108 inv_set_accel_calibration
|
||||
0x02, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_00 inv_set_compass_calibration
|
||||
0x02, 0x44, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_01
|
||||
0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_02
|
||||
0x02, 0x4C, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_10
|
||||
0x02, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_11
|
||||
0x02, 0x54, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_12
|
||||
0x02, 0x58, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_20
|
||||
0x02, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_21
|
||||
0x02, 0xBC, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_22
|
||||
0x01, 0xEC, 0x04, 0x00, 0x00, 0x40, 0x00, // D_1_236 inv_apply_endian_accel
|
||||
0x03, 0x7F, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, // FCFG_2 inv_set_mpu_sensors
|
||||
0x04, 0x02, 0x03, 0x0D, 0x35, 0x5D, // CFG_MOTION_BIAS inv_turn_on_bias_from_no_motion
|
||||
0x04, 0x09, 0x04, 0x87, 0x2D, 0x35, 0x3D, // FCFG_5 inv_set_bias_update
|
||||
0x00, 0xA3, 0x01, 0x00, // D_0_163 inv_set_dead_zone
|
||||
// SPECIAL 0x01 = enable interrupts
|
||||
0x00, 0x00, 0x00, 0x01, // SET INT_ENABLE at i=22, SPECIAL INSTRUCTION
|
||||
0x07, 0x86, 0x01, 0xFE, // CFG_6 inv_set_fifo_interupt
|
||||
0x07, 0x41, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // CFG_8 inv_send_quaternion
|
||||
0x07, 0x7E, 0x01, 0x30, // CFG_16 inv_set_footer
|
||||
0x07, 0x46, 0x01, 0x9A, // CFG_GYRO_SOURCE inv_send_gyro
|
||||
0x07, 0x47, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_9 inv_send_gyro -> inv_construct3_fifo
|
||||
0x07, 0x6C, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_12 inv_send_accel -> inv_construct3_fifo
|
||||
0x02, 0x16, 0x02, 0x00, 0x01 // D_0_22 inv_set_fifo_rate
|
||||
|
||||
// This very last 0x01 WAS a 0x09, which drops the FIFO rate down to 20 Hz. 0x07 is 25 Hz,
|
||||
// 0x01 is 100Hz. Going faster than 100Hz (0x00=200Hz) tends to result in very noisy data.
|
||||
// DMP output frequency is calculated easily using this equation: (200Hz / (1 + value))
|
||||
|
||||
// It is important to make sure the host processor can keep up with reading and processing
|
||||
// the FIFO output at the desired rate. Handling FIFO overflow cleanly is also a good idea.
|
||||
};
|
||||
|
||||
const unsigned char dmpUpdates[MPU6050_DMP_UPDATES_SIZE] PROGMEM = {
|
||||
0x01, 0xB2, 0x02, 0xFF, 0xFF,
|
||||
0x01, 0x90, 0x04, 0x09, 0x23, 0xA1, 0x35,
|
||||
0x01, 0x6A, 0x02, 0x06, 0x00,
|
||||
0x01, 0x60, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00,
|
||||
0x01, 0x62, 0x02, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x00, 0x40, 0x00, 0x00
|
||||
};
|
||||
|
||||
uint8_t MPU6050::dmpInitialize() {
|
||||
// reset device
|
||||
DEBUG_PRINTLN(F("\n\nResetting MPU6050..."));
|
||||
reset();
|
||||
delay(30); // wait after reset
|
||||
|
||||
// enable sleep mode and wake cycle
|
||||
/*Serial.println(F("Enabling sleep mode..."));
|
||||
setSleepEnabled(true);
|
||||
Serial.println(F("Enabling wake cycle..."));
|
||||
setWakeCycleEnabled(true);*/
|
||||
|
||||
// disable sleep mode
|
||||
DEBUG_PRINTLN(F("Disabling sleep mode..."));
|
||||
setSleepEnabled(false);
|
||||
|
||||
// get MPU hardware revision
|
||||
DEBUG_PRINTLN(F("Selecting user bank 16..."));
|
||||
setMemoryBank(0x10, true, true);
|
||||
DEBUG_PRINTLN(F("Selecting memory byte 6..."));
|
||||
setMemoryStartAddress(0x06);
|
||||
DEBUG_PRINTLN(F("Checking hardware revision..."));
|
||||
uint8_t hwRevision = readMemoryByte();
|
||||
DEBUG_PRINT(F("Revision @ user[16][6] = "));
|
||||
DEBUG_PRINTLNF(hwRevision, HEX);
|
||||
DEBUG_PRINTLN(F("Resetting memory bank selection to 0..."));
|
||||
setMemoryBank(0, false, false);
|
||||
|
||||
// check OTP bank valid
|
||||
DEBUG_PRINTLN(F("Reading OTP bank valid flag..."));
|
||||
uint8_t otpValid = getOTPBankValid();
|
||||
DEBUG_PRINT(F("OTP bank is "));
|
||||
DEBUG_PRINTLN(otpValid ? F("valid!") : F("invalid!"));
|
||||
|
||||
// get X/Y/Z gyro offsets
|
||||
DEBUG_PRINTLN(F("Reading gyro offset TC values..."));
|
||||
int8_t xgOffsetTC = getXGyroOffsetTC();
|
||||
int8_t ygOffsetTC = getYGyroOffsetTC();
|
||||
int8_t zgOffsetTC = getZGyroOffsetTC();
|
||||
DEBUG_PRINT(F("X gyro offset = "));
|
||||
DEBUG_PRINTLN(xgOffset);
|
||||
DEBUG_PRINT(F("Y gyro offset = "));
|
||||
DEBUG_PRINTLN(ygOffset);
|
||||
DEBUG_PRINT(F("Z gyro offset = "));
|
||||
DEBUG_PRINTLN(zgOffset);
|
||||
|
||||
// setup weird slave stuff (?)
|
||||
DEBUG_PRINTLN(F("Setting slave 0 address to 0x7F..."));
|
||||
setSlaveAddress(0, 0x7F);
|
||||
DEBUG_PRINTLN(F("Disabling I2C Master mode..."));
|
||||
setI2CMasterModeEnabled(false);
|
||||
DEBUG_PRINTLN(F("Setting slave 0 address to 0x68 (self)..."));
|
||||
setSlaveAddress(0, 0x68);
|
||||
DEBUG_PRINTLN(F("Resetting I2C Master control..."));
|
||||
resetI2CMaster();
|
||||
delay(20);
|
||||
|
||||
// load DMP code into memory banks
|
||||
DEBUG_PRINT(F("Writing DMP code to MPU memory banks ("));
|
||||
DEBUG_PRINT(MPU6050_DMP_CODE_SIZE);
|
||||
DEBUG_PRINTLN(F(" bytes)"));
|
||||
if (writeProgMemoryBlock(dmpMemory, MPU6050_DMP_CODE_SIZE)) {
|
||||
DEBUG_PRINTLN(F("Success! DMP code written and verified."));
|
||||
|
||||
// write DMP configuration
|
||||
DEBUG_PRINT(F("Writing DMP configuration to MPU memory banks ("));
|
||||
DEBUG_PRINT(MPU6050_DMP_CONFIG_SIZE);
|
||||
DEBUG_PRINTLN(F(" bytes in config def)"));
|
||||
if (writeProgDMPConfigurationSet(dmpConfig, MPU6050_DMP_CONFIG_SIZE)) {
|
||||
DEBUG_PRINTLN(F("Success! DMP configuration written and verified."));
|
||||
|
||||
DEBUG_PRINTLN(F("Setting clock source to Z Gyro..."));
|
||||
setClockSource(MPU6050_CLOCK_PLL_ZGYRO);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DMP and FIFO_OFLOW interrupts enabled..."));
|
||||
setIntEnabled(0x12);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting sample rate to 200Hz..."));
|
||||
setRate(4); // 1khz / (1 + 4) = 200 Hz
|
||||
|
||||
DEBUG_PRINTLN(F("Setting external frame sync to TEMP_OUT_L[0]..."));
|
||||
setExternalFrameSync(MPU6050_EXT_SYNC_TEMP_OUT_L);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DLPF bandwidth to 42Hz..."));
|
||||
setDLPFMode(MPU6050_DLPF_BW_42);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting gyro sensitivity to +/- 2000 deg/sec..."));
|
||||
setFullScaleGyroRange(MPU6050_GYRO_FS_2000);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DMP configuration bytes (function unknown)..."));
|
||||
setDMPConfig1(0x03);
|
||||
setDMPConfig2(0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Clearing OTP Bank flag..."));
|
||||
setOTPBankValid(false);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting X/Y/Z gyro offset TCs to previous values..."));
|
||||
setXGyroOffsetTC(xgOffsetTC);
|
||||
setYGyroOffsetTC(ygOffsetTC);
|
||||
setZGyroOffsetTC(zgOffsetTC);
|
||||
|
||||
//DEBUG_PRINTLN(F("Setting X/Y/Z gyro user offsets to zero..."));
|
||||
//setXGyroOffset(0);
|
||||
//setYGyroOffset(0);
|
||||
//setZGyroOffset(0);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 1/7 (function unknown)..."));
|
||||
uint8_t dmpUpdate[16], j;
|
||||
uint16_t pos = 0;
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 2/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO..."));
|
||||
resetFIFO();
|
||||
|
||||
DEBUG_PRINTLN(F("Reading FIFO count..."));
|
||||
uint16_t fifoCount = getFIFOCount();
|
||||
uint8_t fifoBuffer[128];
|
||||
|
||||
DEBUG_PRINT(F("Current FIFO count="));
|
||||
DEBUG_PRINTLN(fifoCount);
|
||||
getFIFOBytes(fifoBuffer, fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting motion detection threshold to 2..."));
|
||||
setMotionDetectionThreshold(2);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting zero-motion detection threshold to 156..."));
|
||||
setZeroMotionDetectionThreshold(156);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting motion detection duration to 80..."));
|
||||
setMotionDetectionDuration(80);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting zero-motion detection duration to 0..."));
|
||||
setZeroMotionDetectionDuration(0);
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO..."));
|
||||
resetFIFO();
|
||||
|
||||
DEBUG_PRINTLN(F("Enabling FIFO..."));
|
||||
setFIFOEnabled(true);
|
||||
|
||||
DEBUG_PRINTLN(F("Enabling DMP..."));
|
||||
setDMPEnabled(true);
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting DMP..."));
|
||||
resetDMP();
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 3/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 4/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 5/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Waiting for FIFO count > 2..."));
|
||||
while ((fifoCount = getFIFOCount()) < 3);
|
||||
|
||||
DEBUG_PRINT(F("Current FIFO count="));
|
||||
DEBUG_PRINTLN(fifoCount);
|
||||
DEBUG_PRINTLN(F("Reading FIFO data..."));
|
||||
getFIFOBytes(fifoBuffer, fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
uint8_t mpuIntStatus = getIntStatus();
|
||||
|
||||
DEBUG_PRINT(F("Current interrupt status="));
|
||||
DEBUG_PRINTLNF(mpuIntStatus, HEX);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading final memory update 6/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
readMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Waiting for FIFO count > 2..."));
|
||||
while ((fifoCount = getFIFOCount()) < 3);
|
||||
|
||||
DEBUG_PRINT(F("Current FIFO count="));
|
||||
DEBUG_PRINTLN(fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading FIFO data..."));
|
||||
getFIFOBytes(fifoBuffer, fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
mpuIntStatus = getIntStatus();
|
||||
|
||||
DEBUG_PRINT(F("Current interrupt status="));
|
||||
DEBUG_PRINTLNF(mpuIntStatus, HEX);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 7/7 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("DMP is good to go! Finally."));
|
||||
|
||||
DEBUG_PRINTLN(F("Disabling DMP (you turn it on later)..."));
|
||||
setDMPEnabled(false);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting up internal 42-byte (default) DMP packet buffer..."));
|
||||
dmpPacketSize = 42;
|
||||
/*if ((dmpPacketBuffer = (uint8_t *)malloc(42)) == 0) {
|
||||
return 3; // TODO: proper error code for no memory
|
||||
}*/
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO and clearing INT status one last time..."));
|
||||
resetFIFO();
|
||||
getIntStatus();
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("ERROR! DMP configuration verification failed."));
|
||||
return 2; // configuration block loading failed
|
||||
}
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("ERROR! DMP code verification failed."));
|
||||
return 1; // main binary block loading failed
|
||||
}
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
bool MPU6050::dmpPacketAvailable() {
|
||||
return getFIFOCount() >= dmpGetFIFOPacketSize();
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpSetFIFORate(uint8_t fifoRate);
|
||||
// uint8_t MPU6050::dmpGetFIFORate();
|
||||
// uint8_t MPU6050::dmpGetSampleStepSizeMS();
|
||||
// uint8_t MPU6050::dmpGetSampleFrequency();
|
||||
// int32_t MPU6050::dmpDecodeTemperature(int8_t tempReg);
|
||||
|
||||
//uint8_t MPU6050::dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority);
|
||||
//uint8_t MPU6050::dmpUnregisterFIFORateProcess(inv_obj_func func);
|
||||
//uint8_t MPU6050::dmpRunFIFORateProcesses();
|
||||
|
||||
// uint8_t MPU6050::dmpSendQuaternion(uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendPacketNumber(uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
|
||||
uint8_t MPU6050::dmpGetAccel(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[28] << 24) + (packet[29] << 16) + (packet[30] << 8) + packet[31]);
|
||||
data[1] = ((packet[32] << 24) + (packet[33] << 16) + (packet[34] << 8) + packet[35]);
|
||||
data[2] = ((packet[36] << 24) + (packet[37] << 16) + (packet[38] << 8) + packet[39]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetAccel(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[28] << 8) + packet[29];
|
||||
data[1] = (packet[32] << 8) + packet[33];
|
||||
data[2] = (packet[36] << 8) + packet[37];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetAccel(VectorInt16 *v, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
v -> x = (packet[28] << 8) + packet[29];
|
||||
v -> y = (packet[32] << 8) + packet[33];
|
||||
v -> z = (packet[36] << 8) + packet[37];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[0] << 24) + (packet[1] << 16) + (packet[2] << 8) + packet[3]);
|
||||
data[1] = ((packet[4] << 24) + (packet[5] << 16) + (packet[6] << 8) + packet[7]);
|
||||
data[2] = ((packet[8] << 24) + (packet[9] << 16) + (packet[10] << 8) + packet[11]);
|
||||
data[3] = ((packet[12] << 24) + (packet[13] << 16) + (packet[14] << 8) + packet[15]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[0] << 8) + packet[1]);
|
||||
data[1] = ((packet[4] << 8) + packet[5]);
|
||||
data[2] = ((packet[8] << 8) + packet[9]);
|
||||
data[3] = ((packet[12] << 8) + packet[13]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
int16_t qI[4];
|
||||
uint8_t status = dmpGetQuaternion(qI, packet);
|
||||
if (status == 0) {
|
||||
q -> w = (float)qI[0] / 16384.0f;
|
||||
q -> x = (float)qI[1] / 16384.0f;
|
||||
q -> y = (float)qI[2] / 16384.0f;
|
||||
q -> z = (float)qI[3] / 16384.0f;
|
||||
return 0;
|
||||
}
|
||||
return status; // int16 return value, indicates error if this line is reached
|
||||
}
|
||||
// uint8_t MPU6050::dmpGet6AxisQuaternion(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetRelativeQuaternion(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetGyro(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[16] << 24) + (packet[17] << 16) + (packet[18] << 8) + packet[19]);
|
||||
data[1] = ((packet[20] << 24) + (packet[21] << 16) + (packet[22] << 8) + packet[23]);
|
||||
data[2] = ((packet[24] << 24) + (packet[25] << 16) + (packet[26] << 8) + packet[27]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetGyro(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[16] << 8) + packet[17];
|
||||
data[1] = (packet[20] << 8) + packet[21];
|
||||
data[2] = (packet[24] << 8) + packet[25];
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpSetLinearAccelFilterCoefficient(float coef);
|
||||
// uint8_t MPU6050::dmpGetLinearAccel(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity) {
|
||||
// get rid of the gravity component (+1g = +8192 in standard DMP FIFO packet, sensitivity is 2g)
|
||||
v -> x = vRaw -> x - gravity -> x*8192;
|
||||
v -> y = vRaw -> y - gravity -> y*8192;
|
||||
v -> z = vRaw -> z - gravity -> z*8192;
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetLinearAccelInWorld(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q) {
|
||||
// rotate measured 3D acceleration vector into original state
|
||||
// frame of reference based on orientation quaternion
|
||||
memcpy(v, vReal, sizeof(VectorInt16));
|
||||
v -> rotate(q);
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetGyroAndAccelSensor(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetGyroSensor(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetControlData(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetTemperature(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetGravity(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetGravity(VectorFloat *v, Quaternion *q) {
|
||||
v -> x = 2 * (q -> x*q -> z - q -> w*q -> y);
|
||||
v -> y = 2 * (q -> w*q -> x + q -> y*q -> z);
|
||||
v -> z = q -> w*q -> w - q -> x*q -> x - q -> y*q -> y + q -> z*q -> z;
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetUnquantizedAccel(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetQuantizedAccel(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetExternalSensorData(long *data, int size, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetEIS(long *data, const uint8_t* packet);
|
||||
|
||||
uint8_t MPU6050::dmpGetEuler(float *data, Quaternion *q) {
|
||||
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // psi
|
||||
data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y); // theta
|
||||
data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1); // phi
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
|
||||
// yaw: (about Z axis)
|
||||
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
|
||||
// pitch: (nose up/down, about Y axis)
|
||||
data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
|
||||
// roll: (tilt left/right, about X axis)
|
||||
data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpGetAccelFloat(float *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetQuaternionFloat(float *data, const uint8_t* packet);
|
||||
|
||||
uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char *dmpData) {
|
||||
/*for (uint8_t k = 0; k < dmpPacketSize; k++) {
|
||||
if (dmpData[k] < 0x10) Serial.print("0");
|
||||
Serial.print(dmpData[k], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.print("\n");*/
|
||||
//Serial.println((uint16_t)dmpPacketBuffer);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed) {
|
||||
uint8_t status;
|
||||
uint8_t buf[dmpPacketSize];
|
||||
for (uint8_t i = 0; i < numPackets; i++) {
|
||||
// read packet from FIFO
|
||||
getFIFOBytes(buf, dmpPacketSize);
|
||||
|
||||
// process packet
|
||||
if ((status = dmpProcessFIFOPacket(buf)) > 0) return status;
|
||||
|
||||
// increment external process count variable, if supplied
|
||||
if (processed != 0) *processed++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpSetFIFOProcessedCallback(void (*func) (void));
|
||||
|
||||
// uint8_t MPU6050::dmpInitFIFOParam();
|
||||
// uint8_t MPU6050::dmpCloseFIFO();
|
||||
// uint8_t MPU6050::dmpSetGyroDataSource(uint_fast8_t source);
|
||||
// uint8_t MPU6050::dmpDecodeQuantizedAccel();
|
||||
// uint32_t MPU6050::dmpGetGyroSumOfSquare();
|
||||
// uint32_t MPU6050::dmpGetAccelSumOfSquare();
|
||||
// void MPU6050::dmpOverrideQuaternion(long *q);
|
||||
uint16_t MPU6050::dmpGetFIFOPacketSize() {
|
||||
return dmpPacketSize;
|
||||
}
|
||||
|
||||
#endif /* _MPU6050_6AXIS_MOTIONAPPS20_H_ */
|
||||
808
digistump-sam/libraries/MPU6050/MPU6050_9Axis_MotionApps41.h
Normal file
808
digistump-sam/libraries/MPU6050/MPU6050_9Axis_MotionApps41.h
Normal file
@@ -0,0 +1,808 @@
|
||||
// I2Cdev library collection - MPU6050 I2C device class, 9-axis MotionApps 4.1 implementation
|
||||
// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
|
||||
// 6/18/2012 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// ... - ongoing debug release
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
#ifndef _MPU6050_9AXIS_MOTIONAPPS41_H_
|
||||
#define _MPU6050_9AXIS_MOTIONAPPS41_H_
|
||||
|
||||
#include "I2Cdev.h"
|
||||
#include "helper_3dmath.h"
|
||||
|
||||
// MotionApps 4.1 DMP implementation, built using the MPU-9150 "MotionFit" board
|
||||
#define MPU6050_INCLUDE_DMP_MOTIONAPPS41
|
||||
|
||||
#include "MPU6050.h"
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
// NOTE! Enabling DEBUG adds about 3.3kB to the flash program size.
|
||||
// Debug output is now working even on ATMega328P MCUs (e.g. Arduino Uno)
|
||||
// after moving string constants to flash memory storage using the F()
|
||||
// compiler macro (Arduino IDE 1.0+ required).
|
||||
|
||||
//#define DEBUG
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINT(x) Serial.print(x)
|
||||
#define DEBUG_PRINTF(x, y) Serial.print(x, y)
|
||||
#define DEBUG_PRINTLN(x) Serial.println(x)
|
||||
#define DEBUG_PRINTLNF(x, y) Serial.println(x, y)
|
||||
#else
|
||||
#define DEBUG_PRINT(x)
|
||||
#define DEBUG_PRINTF(x, y)
|
||||
#define DEBUG_PRINTLN(x)
|
||||
#define DEBUG_PRINTLNF(x, y)
|
||||
#endif
|
||||
|
||||
#define MPU6050_DMP_CODE_SIZE 1962 // dmpMemory[]
|
||||
#define MPU6050_DMP_CONFIG_SIZE 232 // dmpConfig[]
|
||||
#define MPU6050_DMP_UPDATES_SIZE 140 // dmpUpdates[]
|
||||
|
||||
/* ================================================================================================ *
|
||||
| Default MotionApps v4.1 48-byte FIFO packet structure: |
|
||||
| |
|
||||
| [QUAT W][ ][QUAT X][ ][QUAT Y][ ][QUAT Z][ ][GYRO X][ ][GYRO Y][ ] |
|
||||
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
||||
| |
|
||||
| [GYRO Z][ ][MAG X ][MAG Y ][MAG Z ][ACC X ][ ][ACC Y ][ ][ACC Z ][ ][ ] |
|
||||
| 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
||||
* ================================================================================================ */
|
||||
|
||||
// this block of memory gets written to the MPU on start-up, and it seems
|
||||
// to be volatile memory, so it has to be done each time (it only takes ~1
|
||||
// second though)
|
||||
const prog_uchar dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = {
|
||||
// bank 0, 256 bytes
|
||||
0xFB, 0x00, 0x00, 0x3E, 0x00, 0x0B, 0x00, 0x36, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
|
||||
0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01,
|
||||
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x03, 0xE8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFE, 0x80, 0x01,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x3E, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCA, 0xE3, 0x09, 0x3E, 0x80, 0x00, 0x00,
|
||||
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
|
||||
0x41, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x2A, 0x00, 0x00, 0x16, 0x55, 0x00, 0x00, 0x21, 0x82,
|
||||
0xFD, 0x87, 0x26, 0x50, 0xFD, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x80, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x02, 0x65, 0x32, 0x00, 0x00, 0x5E, 0xC0,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFB, 0x8C, 0x6F, 0x5D, 0xFD, 0x5D, 0x08, 0xD9, 0x00, 0x7C, 0x73, 0x3B, 0x00, 0x6C, 0x12, 0xCC,
|
||||
0x32, 0x00, 0x13, 0x9D, 0x32, 0x00, 0xD0, 0xD6, 0x32, 0x00, 0x08, 0x00, 0x40, 0x00, 0x01, 0xF4,
|
||||
0xFF, 0xE6, 0x80, 0x79, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xD6, 0x00, 0x00, 0x27, 0x10,
|
||||
|
||||
// bank 1, 256 bytes
|
||||
0xFB, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFA, 0x36, 0xFF, 0xBC, 0x30, 0x8E, 0x00, 0x05, 0xFB, 0xF0, 0xFF, 0xD9, 0x5B, 0xC8,
|
||||
0xFF, 0xD0, 0x9A, 0xBE, 0x00, 0x00, 0x10, 0xA9, 0xFF, 0xF4, 0x1E, 0xB2, 0x00, 0xCE, 0xBB, 0xF7,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x0C,
|
||||
0xFF, 0xC2, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xCF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x68, 0xB6, 0x79, 0x35, 0x28, 0xBC, 0xC6, 0x7E, 0xD1, 0x6C,
|
||||
0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x30,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x25, 0x4D, 0x00, 0x2F, 0x70, 0x6D, 0x00, 0x00, 0x05, 0xAE, 0x00, 0x0C, 0x02, 0xD0,
|
||||
|
||||
// bank 2, 256 bytes
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0xFF, 0xEF, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x78, 0xA2,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
// bank 3, 256 bytes
|
||||
0xD8, 0xDC, 0xF4, 0xD8, 0xB9, 0xAB, 0xF3, 0xF8, 0xFA, 0xF1, 0xBA, 0xA2, 0xDE, 0xB2, 0xB8, 0xB4,
|
||||
0xA8, 0x81, 0x98, 0xF7, 0x4A, 0x90, 0x7F, 0x91, 0x6A, 0xF3, 0xF9, 0xDB, 0xA8, 0xF9, 0xB0, 0xBA,
|
||||
0xA0, 0x80, 0xF2, 0xCE, 0x81, 0xF3, 0xC2, 0xF1, 0xC1, 0xF2, 0xC3, 0xF3, 0xCC, 0xA2, 0xB2, 0x80,
|
||||
0xF1, 0xC6, 0xD8, 0x80, 0xBA, 0xA7, 0xDF, 0xDF, 0xDF, 0xF2, 0xA7, 0xC3, 0xCB, 0xC5, 0xB6, 0xF0,
|
||||
0x87, 0xA2, 0x94, 0x24, 0x48, 0x70, 0x3C, 0x95, 0x40, 0x68, 0x34, 0x58, 0x9B, 0x78, 0xA2, 0xF1,
|
||||
0x83, 0x92, 0x2D, 0x55, 0x7D, 0xD8, 0xB1, 0xB4, 0xB8, 0xA1, 0xD0, 0x91, 0x80, 0xF2, 0x70, 0xF3,
|
||||
0x70, 0xF2, 0x7C, 0x80, 0xA8, 0xF1, 0x01, 0xB0, 0x98, 0x87, 0xD9, 0x43, 0xD8, 0x86, 0xC9, 0x88,
|
||||
0xBA, 0xA1, 0xF2, 0x0E, 0xB8, 0x97, 0x80, 0xF1, 0xA9, 0xDF, 0xDF, 0xDF, 0xAA, 0xDF, 0xDF, 0xDF,
|
||||
0xF2, 0xAA, 0xC5, 0xCD, 0xC7, 0xA9, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, 0x97, 0xF1, 0xA9, 0x89,
|
||||
0x26, 0x46, 0x66, 0xB0, 0xB4, 0xBA, 0x80, 0xAC, 0xDE, 0xF2, 0xCA, 0xF1, 0xB2, 0x8C, 0x02, 0xA9,
|
||||
0xB6, 0x98, 0x00, 0x89, 0x0E, 0x16, 0x1E, 0xB8, 0xA9, 0xB4, 0x99, 0x2C, 0x54, 0x7C, 0xB0, 0x8A,
|
||||
0xA8, 0x96, 0x36, 0x56, 0x76, 0xF1, 0xB9, 0xAF, 0xB4, 0xB0, 0x83, 0xC0, 0xB8, 0xA8, 0x97, 0x11,
|
||||
0xB1, 0x8F, 0x98, 0xB9, 0xAF, 0xF0, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0xF1, 0xA3, 0x29, 0x55,
|
||||
0x7D, 0xAF, 0x83, 0xB5, 0x93, 0xF0, 0x00, 0x28, 0x50, 0xF5, 0xBA, 0xAD, 0x8F, 0x9F, 0x28, 0x54,
|
||||
0x7C, 0xB9, 0xF1, 0xA3, 0x86, 0x9F, 0x61, 0xA6, 0xDA, 0xDE, 0xDF, 0xDB, 0xB2, 0xB6, 0x8E, 0x9D,
|
||||
0xAE, 0xF5, 0x60, 0x68, 0x70, 0xB1, 0xB5, 0xF1, 0xDA, 0xA6, 0xDF, 0xD9, 0xA6, 0xFA, 0xA3, 0x86,
|
||||
|
||||
// bank 4, 256 bytes
|
||||
0x96, 0xDB, 0x31, 0xA6, 0xD9, 0xF8, 0xDF, 0xBA, 0xA6, 0x8F, 0xC2, 0xC5, 0xC7, 0xB2, 0x8C, 0xC1,
|
||||
0xB8, 0xA2, 0xDF, 0xDF, 0xDF, 0xA3, 0xDF, 0xDF, 0xDF, 0xD8, 0xD8, 0xF1, 0xB8, 0xA8, 0xB2, 0x86,
|
||||
0xB4, 0x98, 0x0D, 0x35, 0x5D, 0xB8, 0xAA, 0x98, 0xB0, 0x87, 0x2D, 0x35, 0x3D, 0xB2, 0xB6, 0xBA,
|
||||
0xAF, 0x8C, 0x96, 0x19, 0x8F, 0x9F, 0xA7, 0x0E, 0x16, 0x1E, 0xB4, 0x9A, 0xB8, 0xAA, 0x87, 0x2C,
|
||||
0x54, 0x7C, 0xB9, 0xA3, 0xDE, 0xDF, 0xDF, 0xA3, 0xB1, 0x80, 0xF2, 0xC4, 0xCD, 0xC9, 0xF1, 0xB8,
|
||||
0xA9, 0xB4, 0x99, 0x83, 0x0D, 0x35, 0x5D, 0x89, 0xB9, 0xA3, 0x2D, 0x55, 0x7D, 0xB5, 0x93, 0xA3,
|
||||
0x0E, 0x16, 0x1E, 0xA9, 0x2C, 0x54, 0x7C, 0xB8, 0xB4, 0xB0, 0xF1, 0x97, 0x83, 0xA8, 0x11, 0x84,
|
||||
0xA5, 0x09, 0x98, 0xA3, 0x83, 0xF0, 0xDA, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0xD8, 0xF1, 0xA5,
|
||||
0x29, 0x55, 0x7D, 0xA5, 0x85, 0x95, 0x02, 0x1A, 0x2E, 0x3A, 0x56, 0x5A, 0x40, 0x48, 0xF9, 0xF3,
|
||||
0xA3, 0xD9, 0xF8, 0xF0, 0x98, 0x83, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0x97, 0x82, 0xA8, 0xF1,
|
||||
0x11, 0xF0, 0x98, 0xA2, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0xDA, 0xF3, 0xDE, 0xD8, 0x83, 0xA5,
|
||||
0x94, 0x01, 0xD9, 0xA3, 0x02, 0xF1, 0xA2, 0xC3, 0xC5, 0xC7, 0xD8, 0xF1, 0x84, 0x92, 0xA2, 0x4D,
|
||||
0xDA, 0x2A, 0xD8, 0x48, 0x69, 0xD9, 0x2A, 0xD8, 0x68, 0x55, 0xDA, 0x32, 0xD8, 0x50, 0x71, 0xD9,
|
||||
0x32, 0xD8, 0x70, 0x5D, 0xDA, 0x3A, 0xD8, 0x58, 0x79, 0xD9, 0x3A, 0xD8, 0x78, 0x93, 0xA3, 0x4D,
|
||||
0xDA, 0x2A, 0xD8, 0x48, 0x69, 0xD9, 0x2A, 0xD8, 0x68, 0x55, 0xDA, 0x32, 0xD8, 0x50, 0x71, 0xD9,
|
||||
0x32, 0xD8, 0x70, 0x5D, 0xDA, 0x3A, 0xD8, 0x58, 0x79, 0xD9, 0x3A, 0xD8, 0x78, 0xA8, 0x8A, 0x9A,
|
||||
|
||||
// bank 5, 256 bytes
|
||||
0xF0, 0x28, 0x50, 0x78, 0x9E, 0xF3, 0x88, 0x18, 0xF1, 0x9F, 0x1D, 0x98, 0xA8, 0xD9, 0x08, 0xD8,
|
||||
0xC8, 0x9F, 0x12, 0x9E, 0xF3, 0x15, 0xA8, 0xDA, 0x12, 0x10, 0xD8, 0xF1, 0xAF, 0xC8, 0x97, 0x87,
|
||||
0x34, 0xB5, 0xB9, 0x94, 0xA4, 0x21, 0xF3, 0xD9, 0x22, 0xD8, 0xF2, 0x2D, 0xF3, 0xD9, 0x2A, 0xD8,
|
||||
0xF2, 0x35, 0xF3, 0xD9, 0x32, 0xD8, 0x81, 0xA4, 0x60, 0x60, 0x61, 0xD9, 0x61, 0xD8, 0x6C, 0x68,
|
||||
0x69, 0xD9, 0x69, 0xD8, 0x74, 0x70, 0x71, 0xD9, 0x71, 0xD8, 0xB1, 0xA3, 0x84, 0x19, 0x3D, 0x5D,
|
||||
0xA3, 0x83, 0x1A, 0x3E, 0x5E, 0x93, 0x10, 0x30, 0x81, 0x10, 0x11, 0xB8, 0xB0, 0xAF, 0x8F, 0x94,
|
||||
0xF2, 0xDA, 0x3E, 0xD8, 0xB4, 0x9A, 0xA8, 0x87, 0x29, 0xDA, 0xF8, 0xD8, 0x87, 0x9A, 0x35, 0xDA,
|
||||
0xF8, 0xD8, 0x87, 0x9A, 0x3D, 0xDA, 0xF8, 0xD8, 0xB1, 0xB9, 0xA4, 0x98, 0x85, 0x02, 0x2E, 0x56,
|
||||
0xA5, 0x81, 0x00, 0x0C, 0x14, 0xA3, 0x97, 0xB0, 0x8A, 0xF1, 0x2D, 0xD9, 0x28, 0xD8, 0x4D, 0xD9,
|
||||
0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0xB1, 0x84, 0x0D, 0xDA, 0x0E, 0xD8, 0xA3, 0x29, 0x83, 0xDA,
|
||||
0x2C, 0x0E, 0xD8, 0xA3, 0x84, 0x49, 0x83, 0xDA, 0x2C, 0x4C, 0x0E, 0xD8, 0xB8, 0xB0, 0x97, 0x86,
|
||||
0xA8, 0x31, 0x9B, 0x06, 0x99, 0x07, 0xAB, 0x97, 0x28, 0x88, 0x9B, 0xF0, 0x0C, 0x20, 0x14, 0x40,
|
||||
0xB9, 0xA3, 0x8A, 0xC3, 0xC5, 0xC7, 0x9A, 0xA3, 0x28, 0x50, 0x78, 0xF1, 0xB5, 0x93, 0x01, 0xD9,
|
||||
0xDF, 0xDF, 0xDF, 0xD8, 0xB8, 0xB4, 0xA8, 0x8C, 0x9C, 0xF0, 0x04, 0x28, 0x51, 0x79, 0x1D, 0x30,
|
||||
0x14, 0x38, 0xB2, 0x82, 0xAB, 0xD0, 0x98, 0x2C, 0x50, 0x50, 0x78, 0x78, 0x9B, 0xF1, 0x1A, 0xB0,
|
||||
0xF0, 0xB1, 0x83, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0xB0, 0x8B, 0x29, 0x51, 0x79, 0xB1, 0x83, 0x24,
|
||||
|
||||
// bank 6, 256 bytes
|
||||
0x70, 0x59, 0xB0, 0x8B, 0x20, 0x58, 0x71, 0xB1, 0x83, 0x44, 0x69, 0x38, 0xB0, 0x8B, 0x39, 0x40,
|
||||
0x68, 0xB1, 0x83, 0x64, 0x48, 0x31, 0xB0, 0x8B, 0x30, 0x49, 0x60, 0xA5, 0x88, 0x20, 0x09, 0x71,
|
||||
0x58, 0x44, 0x68, 0x11, 0x39, 0x64, 0x49, 0x30, 0x19, 0xF1, 0xAC, 0x00, 0x2C, 0x54, 0x7C, 0xF0,
|
||||
0x8C, 0xA8, 0x04, 0x28, 0x50, 0x78, 0xF1, 0x88, 0x97, 0x26, 0xA8, 0x59, 0x98, 0xAC, 0x8C, 0x02,
|
||||
0x26, 0x46, 0x66, 0xF0, 0x89, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38,
|
||||
0x64, 0x48, 0x31, 0xA9, 0x88, 0x09, 0x20, 0x59, 0x70, 0xAB, 0x11, 0x38, 0x40, 0x69, 0xA8, 0x19,
|
||||
0x31, 0x48, 0x60, 0x8C, 0xA8, 0x3C, 0x41, 0x5C, 0x20, 0x7C, 0x00, 0xF1, 0x87, 0x98, 0x19, 0x86,
|
||||
0xA8, 0x6E, 0x76, 0x7E, 0xA9, 0x99, 0x88, 0x2D, 0x55, 0x7D, 0x9E, 0xB9, 0xA3, 0x8A, 0x22, 0x8A,
|
||||
0x6E, 0x8A, 0x56, 0x8A, 0x5E, 0x9F, 0xB1, 0x83, 0x06, 0x26, 0x46, 0x66, 0x0E, 0x2E, 0x4E, 0x6E,
|
||||
0x9D, 0xB8, 0xAD, 0x00, 0x2C, 0x54, 0x7C, 0xF2, 0xB1, 0x8C, 0xB4, 0x99, 0xB9, 0xA3, 0x2D, 0x55,
|
||||
0x7D, 0x81, 0x91, 0xAC, 0x38, 0xAD, 0x3A, 0xB5, 0x83, 0x91, 0xAC, 0x2D, 0xD9, 0x28, 0xD8, 0x4D,
|
||||
0xD9, 0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0x8C, 0x9D, 0xAE, 0x29, 0xD9, 0x04, 0xAE, 0xD8, 0x51,
|
||||
0xD9, 0x04, 0xAE, 0xD8, 0x79, 0xD9, 0x04, 0xD8, 0x81, 0xF3, 0x9D, 0xAD, 0x00, 0x8D, 0xAE, 0x19,
|
||||
0x81, 0xAD, 0xD9, 0x01, 0xD8, 0xF2, 0xAE, 0xDA, 0x26, 0xD8, 0x8E, 0x91, 0x29, 0x83, 0xA7, 0xD9,
|
||||
0xAD, 0xAD, 0xAD, 0xAD, 0xF3, 0x2A, 0xD8, 0xD8, 0xF1, 0xB0, 0xAC, 0x89, 0x91, 0x3E, 0x5E, 0x76,
|
||||
0xF3, 0xAC, 0x2E, 0x2E, 0xF1, 0xB1, 0x8C, 0x5A, 0x9C, 0xAC, 0x2C, 0x28, 0x28, 0x28, 0x9C, 0xAC,
|
||||
|
||||
// bank 7, 170 bytes (remainder)
|
||||
0x30, 0x18, 0xA8, 0x98, 0x81, 0x28, 0x34, 0x3C, 0x97, 0x24, 0xA7, 0x28, 0x34, 0x3C, 0x9C, 0x24,
|
||||
0xF2, 0xB0, 0x89, 0xAC, 0x91, 0x2C, 0x4C, 0x6C, 0x8A, 0x9B, 0x2D, 0xD9, 0xD8, 0xD8, 0x51, 0xD9,
|
||||
0xD8, 0xD8, 0x79, 0xD9, 0xD8, 0xD8, 0xF1, 0x9E, 0x88, 0xA3, 0x31, 0xDA, 0xD8, 0xD8, 0x91, 0x2D,
|
||||
0xD9, 0x28, 0xD8, 0x4D, 0xD9, 0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0xB1, 0x83, 0x93, 0x35, 0x3D,
|
||||
0x80, 0x25, 0xDA, 0xD8, 0xD8, 0x85, 0x69, 0xDA, 0xD8, 0xD8, 0xB4, 0x93, 0x81, 0xA3, 0x28, 0x34,
|
||||
0x3C, 0xF3, 0xAB, 0x8B, 0xA3, 0x91, 0xB6, 0x09, 0xB4, 0xD9, 0xAB, 0xDE, 0xB0, 0x87, 0x9C, 0xB9,
|
||||
0xA3, 0xDD, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x95, 0xF1, 0xA3, 0xA3, 0xA3, 0x9D, 0xF1, 0xA3, 0xA3,
|
||||
0xA3, 0xA3, 0xF2, 0xA3, 0xB4, 0x90, 0x80, 0xF2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3,
|
||||
0xA3, 0xA3, 0xB2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xB0, 0x87, 0xB5, 0x99, 0xF1, 0xA3, 0xA3,
|
||||
0xA3, 0x98, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x97, 0xA3, 0xA3, 0xA3, 0xA3, 0xF3, 0x9B, 0xA3, 0xA3,
|
||||
0xDC, 0xB9, 0xA7, 0xF1, 0x26, 0x26, 0x26, 0xD8, 0xD8, 0xFF
|
||||
};
|
||||
|
||||
const prog_uchar dmpConfig[MPU6050_DMP_CONFIG_SIZE] PROGMEM = {
|
||||
// BANK OFFSET LENGTH [DATA]
|
||||
0x02, 0xEC, 0x04, 0x00, 0x47, 0x7D, 0x1A, // ?
|
||||
0x03, 0x82, 0x03, 0x4C, 0xCD, 0x6C, // FCFG_1 inv_set_gyro_calibration
|
||||
0x03, 0xB2, 0x03, 0x36, 0x56, 0x76, // FCFG_3 inv_set_gyro_calibration
|
||||
0x00, 0x68, 0x04, 0x02, 0xCA, 0xE3, 0x09, // D_0_104 inv_set_gyro_calibration
|
||||
0x01, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // D_1_152 inv_set_accel_calibration
|
||||
0x03, 0x86, 0x03, 0x0C, 0xC9, 0x2C, // FCFG_2 inv_set_accel_calibration
|
||||
0x03, 0x90, 0x03, 0x26, 0x46, 0x66, // (continued)...FCFG_2 inv_set_accel_calibration
|
||||
0x00, 0x6C, 0x02, 0x40, 0x00, // D_0_108 inv_set_accel_calibration
|
||||
|
||||
0x02, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_00 inv_set_compass_calibration
|
||||
0x02, 0x44, 0x04, 0x40, 0x00, 0x00, 0x00, // CPASS_MTX_01
|
||||
0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_02
|
||||
0x02, 0x4C, 0x04, 0x40, 0x00, 0x00, 0x00, // CPASS_MTX_10
|
||||
0x02, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_11
|
||||
0x02, 0x54, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_12
|
||||
0x02, 0x58, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_20
|
||||
0x02, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_21
|
||||
0x02, 0xBC, 0x04, 0xC0, 0x00, 0x00, 0x00, // CPASS_MTX_22
|
||||
|
||||
0x01, 0xEC, 0x04, 0x00, 0x00, 0x40, 0x00, // D_1_236 inv_apply_endian_accel
|
||||
0x03, 0x86, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, // FCFG_2 inv_set_mpu_sensors
|
||||
0x04, 0x22, 0x03, 0x0D, 0x35, 0x5D, // CFG_MOTION_BIAS inv_turn_on_bias_from_no_motion
|
||||
0x00, 0xA3, 0x01, 0x00, // ?
|
||||
0x04, 0x29, 0x04, 0x87, 0x2D, 0x35, 0x3D, // FCFG_5 inv_set_bias_update
|
||||
0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // CFG_8 inv_send_quaternion
|
||||
0x07, 0x9F, 0x01, 0x30, // CFG_16 inv_set_footer
|
||||
0x07, 0x67, 0x01, 0x9A, // CFG_GYRO_SOURCE inv_send_gyro
|
||||
0x07, 0x68, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_9 inv_send_gyro -> inv_construct3_fifo
|
||||
0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // ?
|
||||
0x02, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // ?
|
||||
0x07, 0x83, 0x06, 0xC2, 0xCA, 0xC4, 0xA3, 0xA3, 0xA3, // ?
|
||||
// SPECIAL 0x01 = enable interrupts
|
||||
0x00, 0x00, 0x00, 0x01, // SET INT_ENABLE, SPECIAL INSTRUCTION
|
||||
0x07, 0xA7, 0x01, 0xFE, // ?
|
||||
0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // ?
|
||||
0x07, 0x67, 0x01, 0x9A, // ?
|
||||
0x07, 0x68, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_12 inv_send_accel -> inv_construct3_fifo
|
||||
0x07, 0x8D, 0x04, 0xF1, 0x28, 0x30, 0x38, // ??? CFG_12 inv_send_mag -> inv_construct3_fifo
|
||||
0x02, 0x16, 0x02, 0x00, 0x03 // D_0_22 inv_set_fifo_rate
|
||||
|
||||
// This very last 0x01 WAS a 0x09, which drops the FIFO rate down to 20 Hz. 0x07 is 25 Hz,
|
||||
// 0x01 is 100Hz. Going faster than 100Hz (0x00=200Hz) tends to result in very noisy data.
|
||||
// DMP output frequency is calculated easily using this equation: (200Hz / (1 + value))
|
||||
|
||||
// It is important to make sure the host processor can keep up with reading and processing
|
||||
// the FIFO output at the desired rate. Handling FIFO overflow cleanly is also a good idea.
|
||||
};
|
||||
|
||||
const prog_uchar dmpUpdates[MPU6050_DMP_UPDATES_SIZE] PROGMEM = {
|
||||
0x01, 0xB2, 0x02, 0xFF, 0xF5,
|
||||
0x01, 0x90, 0x04, 0x0A, 0x0D, 0x97, 0xC0,
|
||||
0x00, 0xA3, 0x01, 0x00,
|
||||
0x04, 0x29, 0x04, 0x87, 0x2D, 0x35, 0x3D,
|
||||
0x01, 0x6A, 0x02, 0x06, 0x00,
|
||||
0x01, 0x60, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00,
|
||||
0x02, 0x60, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x08, 0x02, 0x01, 0x20,
|
||||
0x01, 0x0A, 0x02, 0x00, 0x4E,
|
||||
0x01, 0x02, 0x02, 0xFE, 0xB3,
|
||||
0x02, 0x6C, 0x04, 0x00, 0x00, 0x00, 0x00, // READ
|
||||
0x02, 0x6C, 0x04, 0xFA, 0xFE, 0x00, 0x00,
|
||||
0x02, 0x60, 0x0C, 0xFF, 0xFF, 0xCB, 0x4D, 0x00, 0x01, 0x08, 0xC1, 0xFF, 0xFF, 0xBC, 0x2C,
|
||||
0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0xF8, 0x04, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0xFC, 0x04, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x60, 0x04, 0x00, 0x40, 0x00, 0x00
|
||||
};
|
||||
|
||||
uint8_t MPU6050::dmpInitialize() {
|
||||
// reset device
|
||||
DEBUG_PRINTLN(F("\n\nResetting MPU6050..."));
|
||||
reset();
|
||||
delay(30); // wait after reset
|
||||
|
||||
// disable sleep mode
|
||||
DEBUG_PRINTLN(F("Disabling sleep mode..."));
|
||||
setSleepEnabled(false);
|
||||
|
||||
// get MPU product ID
|
||||
DEBUG_PRINTLN(F("Getting product ID..."));
|
||||
//uint8_t productID = 0; //getProductID();
|
||||
DEBUG_PRINT(F("Product ID = "));
|
||||
DEBUG_PRINT(productID);
|
||||
|
||||
// get MPU hardware revision
|
||||
DEBUG_PRINTLN(F("Selecting user bank 16..."));
|
||||
setMemoryBank(0x10, true, true);
|
||||
DEBUG_PRINTLN(F("Selecting memory byte 6..."));
|
||||
setMemoryStartAddress(0x06);
|
||||
DEBUG_PRINTLN(F("Checking hardware revision..."));
|
||||
uint8_t hwRevision = readMemoryByte();
|
||||
DEBUG_PRINT(F("Revision @ user[16][6] = "));
|
||||
DEBUG_PRINTLNF(hwRevision, HEX);
|
||||
DEBUG_PRINTLN(F("Resetting memory bank selection to 0..."));
|
||||
setMemoryBank(0, false, false);
|
||||
|
||||
// check OTP bank valid
|
||||
DEBUG_PRINTLN(F("Reading OTP bank valid flag..."));
|
||||
uint8_t otpValid = getOTPBankValid();
|
||||
DEBUG_PRINT(F("OTP bank is "));
|
||||
DEBUG_PRINTLN(otpValid ? F("valid!") : F("invalid!"));
|
||||
|
||||
// get X/Y/Z gyro offsets
|
||||
DEBUG_PRINTLN(F("Reading gyro offset values..."));
|
||||
int8_t xgOffset = getXGyroOffset();
|
||||
int8_t ygOffset = getYGyroOffset();
|
||||
int8_t zgOffset = getZGyroOffset();
|
||||
DEBUG_PRINT(F("X gyro offset = "));
|
||||
DEBUG_PRINTLN(xgOffset);
|
||||
DEBUG_PRINT(F("Y gyro offset = "));
|
||||
DEBUG_PRINTLN(ygOffset);
|
||||
DEBUG_PRINT(F("Z gyro offset = "));
|
||||
DEBUG_PRINTLN(zgOffset);
|
||||
|
||||
I2Cdev::readByte(devAddr, MPU6050_RA_USER_CTRL, buffer); // ?
|
||||
|
||||
DEBUG_PRINTLN(F("Enabling interrupt latch, clear on any read, AUX bypass enabled"));
|
||||
I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x32);
|
||||
|
||||
// enable MPU AUX I2C bypass mode
|
||||
//DEBUG_PRINTLN(F("Enabling AUX I2C bypass mode..."));
|
||||
//setI2CBypassEnabled(true);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting magnetometer mode to power-down..."));
|
||||
//mag -> setMode(0);
|
||||
I2Cdev::writeByte(0x0E, 0x0A, 0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting magnetometer mode to fuse access..."));
|
||||
//mag -> setMode(0x0F);
|
||||
I2Cdev::writeByte(0x0E, 0x0A, 0x0F);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading mag magnetometer factory calibration..."));
|
||||
int8_t asax, asay, asaz;
|
||||
//mag -> getAdjustment(&asax, &asay, &asaz);
|
||||
I2Cdev::readBytes(0x0E, 0x10, 3, buffer);
|
||||
asax = (int8_t)buffer[0];
|
||||
asay = (int8_t)buffer[1];
|
||||
asaz = (int8_t)buffer[2];
|
||||
DEBUG_PRINT(F("Adjustment X/Y/Z = "));
|
||||
DEBUG_PRINT(asax);
|
||||
DEBUG_PRINT(F(" / "));
|
||||
DEBUG_PRINT(asay);
|
||||
DEBUG_PRINT(F(" / "));
|
||||
DEBUG_PRINTLN(asaz);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting magnetometer mode to power-down..."));
|
||||
//mag -> setMode(0);
|
||||
I2Cdev::writeByte(0x0E, 0x0A, 0x00);
|
||||
|
||||
// load DMP code into memory banks
|
||||
DEBUG_PRINT(F("Writing DMP code to MPU memory banks ("));
|
||||
DEBUG_PRINT(MPU6050_DMP_CODE_SIZE);
|
||||
DEBUG_PRINTLN(F(" bytes)"));
|
||||
if (writeProgMemoryBlock(dmpMemory, MPU6050_DMP_CODE_SIZE)) {
|
||||
DEBUG_PRINTLN(F("Success! DMP code written and verified."));
|
||||
|
||||
DEBUG_PRINTLN(F("Configuring DMP and related settings..."));
|
||||
|
||||
// write DMP configuration
|
||||
DEBUG_PRINT(F("Writing DMP configuration to MPU memory banks ("));
|
||||
DEBUG_PRINT(MPU6050_DMP_CONFIG_SIZE);
|
||||
DEBUG_PRINTLN(F(" bytes in config def)"));
|
||||
if (writeProgDMPConfigurationSet(dmpConfig, MPU6050_DMP_CONFIG_SIZE)) {
|
||||
DEBUG_PRINTLN(F("Success! DMP configuration written and verified."));
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DMP and FIFO_OFLOW interrupts enabled..."));
|
||||
setIntEnabled(0x12);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting sample rate to 200Hz..."));
|
||||
setRate(4); // 1khz / (1 + 4) = 200 Hz
|
||||
|
||||
DEBUG_PRINTLN(F("Setting clock source to Z Gyro..."));
|
||||
setClockSource(MPU6050_CLOCK_PLL_ZGYRO);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DLPF bandwidth to 42Hz..."));
|
||||
setDLPFMode(MPU6050_DLPF_BW_42);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting external frame sync to TEMP_OUT_L[0]..."));
|
||||
setExternalFrameSync(MPU6050_EXT_SYNC_TEMP_OUT_L);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting gyro sensitivity to +/- 2000 deg/sec..."));
|
||||
setFullScaleGyroRange(MPU6050_GYRO_FS_2000);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting DMP configuration bytes (function unknown)..."));
|
||||
setDMPConfig1(0x03);
|
||||
setDMPConfig2(0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Clearing OTP Bank flag..."));
|
||||
setOTPBankValid(false);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting X/Y/Z gyro offsets to previous values..."));
|
||||
setXGyroOffset(xgOffset);
|
||||
setYGyroOffset(ygOffset);
|
||||
setZGyroOffset(zgOffset);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting X/Y/Z gyro user offsets to zero..."));
|
||||
setXGyroOffsetUser(0);
|
||||
setYGyroOffsetUser(0);
|
||||
setZGyroOffsetUser(0);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 1/19 (function unknown)..."));
|
||||
uint8_t dmpUpdate[16], j;
|
||||
uint16_t pos = 0;
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 2/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO..."));
|
||||
resetFIFO();
|
||||
|
||||
DEBUG_PRINTLN(F("Reading FIFO count..."));
|
||||
uint8_t fifoCount = getFIFOCount();
|
||||
|
||||
DEBUG_PRINT(F("Current FIFO count="));
|
||||
DEBUG_PRINTLN(fifoCount);
|
||||
uint8_t fifoBuffer[128];
|
||||
//getFIFOBytes(fifoBuffer, fifoCount);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 3/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 4/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Disabling all standby flags..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_PWR_MGMT_2, 0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting accelerometer sensitivity to +/- 2g..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_ACCEL_CONFIG, 0x00);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting motion detection threshold to 2..."));
|
||||
setMotionDetectionThreshold(2);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting zero-motion detection threshold to 156..."));
|
||||
setZeroMotionDetectionThreshold(156);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting motion detection duration to 80..."));
|
||||
setMotionDetectionDuration(80);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting zero-motion detection duration to 0..."));
|
||||
setZeroMotionDetectionDuration(0);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting AK8975 to single measurement mode..."));
|
||||
//mag -> setMode(1);
|
||||
I2Cdev::writeByte(0x0E, 0x0A, 0x01);
|
||||
|
||||
// setup AK8975 (0x0E) as Slave 0 in read mode
|
||||
DEBUG_PRINTLN(F("Setting up AK8975 read slave 0..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_ADDR, 0x8E);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_REG, 0x01);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_CTRL, 0xDA);
|
||||
|
||||
// setup AK8975 (0x0E) as Slave 2 in write mode
|
||||
DEBUG_PRINTLN(F("Setting up AK8975 write slave 2..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_ADDR, 0x0E);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_REG, 0x0A);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_CTRL, 0x81);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_DO, 0x01);
|
||||
|
||||
// setup I2C timing/delay control
|
||||
DEBUG_PRINTLN(F("Setting up slave access delay..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV4_CTRL, 0x18);
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_I2C_MST_DELAY_CTRL, 0x05);
|
||||
|
||||
// enable interrupts
|
||||
DEBUG_PRINTLN(F("Enabling default interrupt behavior/no bypass..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_INT_PIN_CFG, 0x00);
|
||||
|
||||
// enable I2C master mode and reset DMP/FIFO
|
||||
DEBUG_PRINTLN(F("Enabling I2C master mode..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x20);
|
||||
DEBUG_PRINTLN(F("Resetting FIFO..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x24);
|
||||
DEBUG_PRINTLN(F("Rewriting I2C master mode enabled because...I don't know"));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x20);
|
||||
DEBUG_PRINTLN(F("Enabling and resetting DMP/FIFO..."));
|
||||
I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0xE8);
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 5/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 6/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 7/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 8/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 9/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 10/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 11/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading final memory update 12/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
readMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
#ifdef DEBUG
|
||||
DEBUG_PRINT(F("Read bytes: "));
|
||||
for (j = 0; j < 4; j++) {
|
||||
DEBUG_PRINTF(dmpUpdate[3 + j], HEX);
|
||||
DEBUG_PRINT(" ");
|
||||
}
|
||||
DEBUG_PRINTLN("");
|
||||
#endif
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 13/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 14/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 15/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 16/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
DEBUG_PRINTLN(F("Writing final memory update 17/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Waiting for FIRO count >= 46..."));
|
||||
while ((fifoCount = getFIFOCount()) < 46);
|
||||
DEBUG_PRINTLN(F("Reading FIFO..."));
|
||||
getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
getIntStatus();
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 18/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Waiting for FIRO count >= 48..."));
|
||||
while ((fifoCount = getFIFOCount()) < 48);
|
||||
DEBUG_PRINTLN(F("Reading FIFO..."));
|
||||
getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
getIntStatus();
|
||||
DEBUG_PRINTLN(F("Waiting for FIRO count >= 48..."));
|
||||
while ((fifoCount = getFIFOCount()) < 48);
|
||||
DEBUG_PRINTLN(F("Reading FIFO..."));
|
||||
getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
|
||||
DEBUG_PRINTLN(F("Reading interrupt status..."));
|
||||
getIntStatus();
|
||||
|
||||
DEBUG_PRINTLN(F("Writing final memory update 19/19 (function unknown)..."));
|
||||
for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
|
||||
writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
|
||||
|
||||
DEBUG_PRINTLN(F("Disabling DMP (you turn it on later)..."));
|
||||
setDMPEnabled(false);
|
||||
|
||||
DEBUG_PRINTLN(F("Setting up internal 48-byte (default) DMP packet buffer..."));
|
||||
dmpPacketSize = 48;
|
||||
/*if ((dmpPacketBuffer = (uint8_t *)malloc(42)) == 0) {
|
||||
return 3; // TODO: proper error code for no memory
|
||||
}*/
|
||||
|
||||
DEBUG_PRINTLN(F("Resetting FIFO and clearing INT status one last time..."));
|
||||
resetFIFO();
|
||||
getIntStatus();
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("ERROR! DMP configuration verification failed."));
|
||||
return 2; // configuration block loading failed
|
||||
}
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("ERROR! DMP code verification failed."));
|
||||
return 1; // main binary block loading failed
|
||||
}
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
bool MPU6050::dmpPacketAvailable() {
|
||||
return getFIFOCount() >= dmpGetFIFOPacketSize();
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpSetFIFORate(uint8_t fifoRate);
|
||||
// uint8_t MPU6050::dmpGetFIFORate();
|
||||
// uint8_t MPU6050::dmpGetSampleStepSizeMS();
|
||||
// uint8_t MPU6050::dmpGetSampleFrequency();
|
||||
// int32_t MPU6050::dmpDecodeTemperature(int8_t tempReg);
|
||||
|
||||
//uint8_t MPU6050::dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority);
|
||||
//uint8_t MPU6050::dmpUnregisterFIFORateProcess(inv_obj_func func);
|
||||
//uint8_t MPU6050::dmpRunFIFORateProcesses();
|
||||
|
||||
// uint8_t MPU6050::dmpSendQuaternion(uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendPacketNumber(uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
// uint8_t MPU6050::dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
|
||||
|
||||
uint8_t MPU6050::dmpGetAccel(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[34] << 24) + (packet[35] << 16) + (packet[36] << 8) + packet[37]);
|
||||
data[1] = ((packet[38] << 24) + (packet[39] << 16) + (packet[40] << 8) + packet[41]);
|
||||
data[2] = ((packet[42] << 24) + (packet[43] << 16) + (packet[44] << 8) + packet[45]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetAccel(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[34] << 8) + packet[35];
|
||||
data[1] = (packet[38] << 8) + packet[39];
|
||||
data[2] = (packet[42] << 8) + packet[43];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetAccel(VectorInt16 *v, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
v -> x = (packet[34] << 8) + packet[35];
|
||||
v -> y = (packet[38] << 8) + packet[39];
|
||||
v -> z = (packet[42] << 8) + packet[43];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[0] << 24) + (packet[1] << 16) + (packet[2] << 8) + packet[3]);
|
||||
data[1] = ((packet[4] << 24) + (packet[5] << 16) + (packet[6] << 8) + packet[7]);
|
||||
data[2] = ((packet[8] << 24) + (packet[9] << 16) + (packet[10] << 8) + packet[11]);
|
||||
data[3] = ((packet[12] << 24) + (packet[13] << 16) + (packet[14] << 8) + packet[15]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[0] << 8) + packet[1]);
|
||||
data[1] = ((packet[4] << 8) + packet[5]);
|
||||
data[2] = ((packet[8] << 8) + packet[9]);
|
||||
data[3] = ((packet[12] << 8) + packet[13]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
int16_t qI[4];
|
||||
uint8_t status = dmpGetQuaternion(qI, packet);
|
||||
if (status == 0) {
|
||||
q -> w = (float)qI[0] / 16384.0f;
|
||||
q -> x = (float)qI[1] / 16384.0f;
|
||||
q -> y = (float)qI[2] / 16384.0f;
|
||||
q -> z = (float)qI[3] / 16384.0f;
|
||||
return 0;
|
||||
}
|
||||
return status; // int16 return value, indicates error if this line is reached
|
||||
}
|
||||
// uint8_t MPU6050::dmpGet6AxisQuaternion(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetRelativeQuaternion(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetGyro(int32_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = ((packet[16] << 24) + (packet[17] << 16) + (packet[18] << 8) + packet[19]);
|
||||
data[1] = ((packet[20] << 24) + (packet[21] << 16) + (packet[22] << 8) + packet[23]);
|
||||
data[2] = ((packet[24] << 24) + (packet[25] << 16) + (packet[26] << 8) + packet[27]);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetGyro(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[16] << 8) + packet[17];
|
||||
data[1] = (packet[20] << 8) + packet[21];
|
||||
data[2] = (packet[24] << 8) + packet[25];
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetMag(int16_t *data, const uint8_t* packet) {
|
||||
// TODO: accommodate different arrangements of sent data (ONLY default supported now)
|
||||
if (packet == 0) packet = dmpPacketBuffer;
|
||||
data[0] = (packet[28] << 8) + packet[29];
|
||||
data[1] = (packet[30] << 8) + packet[31];
|
||||
data[2] = (packet[32] << 8) + packet[33];
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpSetLinearAccelFilterCoefficient(float coef);
|
||||
// uint8_t MPU6050::dmpGetLinearAccel(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity) {
|
||||
// get rid of the gravity component (+1g = +4096 in standard DMP FIFO packet)
|
||||
v -> x = vRaw -> x - gravity -> x*4096;
|
||||
v -> y = vRaw -> y - gravity -> y*4096;
|
||||
v -> z = vRaw -> z - gravity -> z*4096;
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetLinearAccelInWorld(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q) {
|
||||
// rotate measured 3D acceleration vector into original state
|
||||
// frame of reference based on orientation quaternion
|
||||
memcpy(v, vReal, sizeof(VectorInt16));
|
||||
v -> rotate(q);
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetGyroAndAccelSensor(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetGyroSensor(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetControlData(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetTemperature(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetGravity(long *data, const uint8_t* packet);
|
||||
uint8_t MPU6050::dmpGetGravity(VectorFloat *v, Quaternion *q) {
|
||||
v -> x = 2 * (q -> x*q -> z - q -> w*q -> y);
|
||||
v -> y = 2 * (q -> w*q -> x + q -> y*q -> z);
|
||||
v -> z = q -> w*q -> w - q -> x*q -> x - q -> y*q -> y + q -> z*q -> z;
|
||||
return 0;
|
||||
}
|
||||
// uint8_t MPU6050::dmpGetUnquantizedAccel(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetQuantizedAccel(long *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetExternalSensorData(long *data, int size, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetEIS(long *data, const uint8_t* packet);
|
||||
|
||||
uint8_t MPU6050::dmpGetEuler(float *data, Quaternion *q) {
|
||||
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // psi
|
||||
data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y); // theta
|
||||
data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1); // phi
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
|
||||
// yaw: (about Z axis)
|
||||
data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
|
||||
// pitch: (nose up/down, about Y axis)
|
||||
data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
|
||||
// roll: (tilt left/right, about X axis)
|
||||
data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpGetAccelFloat(float *data, const uint8_t* packet);
|
||||
// uint8_t MPU6050::dmpGetQuaternionFloat(float *data, const uint8_t* packet);
|
||||
|
||||
uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char *dmpData) {
|
||||
/*for (uint8_t k = 0; k < dmpPacketSize; k++) {
|
||||
if (dmpData[k] < 0x10) Serial.print("0");
|
||||
Serial.print(dmpData[k], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.print("\n");*/
|
||||
//Serial.println((uint16_t)dmpPacketBuffer);
|
||||
return 0;
|
||||
}
|
||||
uint8_t MPU6050::dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed) {
|
||||
uint8_t status;
|
||||
uint8_t buf[dmpPacketSize];
|
||||
for (uint8_t i = 0; i < numPackets; i++) {
|
||||
// read packet from FIFO
|
||||
getFIFOBytes(buf, dmpPacketSize);
|
||||
|
||||
// process packet
|
||||
if ((status = dmpProcessFIFOPacket(buf)) > 0) return status;
|
||||
|
||||
// increment external process count variable, if supplied
|
||||
if (processed != 0) *processed++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// uint8_t MPU6050::dmpSetFIFOProcessedCallback(void (*func) (void));
|
||||
|
||||
// uint8_t MPU6050::dmpInitFIFOParam();
|
||||
// uint8_t MPU6050::dmpCloseFIFO();
|
||||
// uint8_t MPU6050::dmpSetGyroDataSource(uint_fast8_t source);
|
||||
// uint8_t MPU6050::dmpDecodeQuantizedAccel();
|
||||
// uint32_t MPU6050::dmpGetGyroSumOfSquare();
|
||||
// uint32_t MPU6050::dmpGetAccelSumOfSquare();
|
||||
// void MPU6050::dmpOverrideQuaternion(long *q);
|
||||
uint16_t MPU6050::dmpGetFIFOPacketSize() {
|
||||
return dmpPacketSize;
|
||||
}
|
||||
|
||||
#endif /* _MPU6050_9AXIS_MOTIONAPPS41_H_ */
|
||||
216
digistump-sam/libraries/MPU6050/helper_3dmath.h
Normal file
216
digistump-sam/libraries/MPU6050/helper_3dmath.h
Normal file
@@ -0,0 +1,216 @@
|
||||
// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class, 3D math helper
|
||||
// 6/5/2012 by Jeff Rowberg <jeff@rowberg.net>
|
||||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
|
||||
//
|
||||
// Changelog:
|
||||
// 2012-06-05 - add 3D math helper file to DMP6 example sketch
|
||||
|
||||
/* ============================================
|
||||
I2Cdev device library code is placed under the MIT license
|
||||
Copyright (c) 2012 Jeff Rowberg
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
===============================================
|
||||
*/
|
||||
|
||||
#ifndef _HELPER_3DMATH_H_
|
||||
#define _HELPER_3DMATH_H_
|
||||
|
||||
class Quaternion {
|
||||
public:
|
||||
float w;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
Quaternion() {
|
||||
w = 1.0f;
|
||||
x = 0.0f;
|
||||
y = 0.0f;
|
||||
z = 0.0f;
|
||||
}
|
||||
|
||||
Quaternion(float nw, float nx, float ny, float nz) {
|
||||
w = nw;
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
Quaternion getProduct(Quaternion q) {
|
||||
// Quaternion multiplication is defined by:
|
||||
// (Q1 * Q2).w = (w1w2 - x1x2 - y1y2 - z1z2)
|
||||
// (Q1 * Q2).x = (w1x2 + x1w2 + y1z2 - z1y2)
|
||||
// (Q1 * Q2).y = (w1y2 - x1z2 + y1w2 + z1x2)
|
||||
// (Q1 * Q2).z = (w1z2 + x1y2 - y1x2 + z1w2
|
||||
return Quaternion(
|
||||
w*q.w - x*q.x - y*q.y - z*q.z, // new w
|
||||
w*q.x + x*q.w + y*q.z - z*q.y, // new x
|
||||
w*q.y - x*q.z + y*q.w + z*q.x, // new y
|
||||
w*q.z + x*q.y - y*q.x + z*q.w); // new z
|
||||
}
|
||||
|
||||
Quaternion getConjugate() {
|
||||
return Quaternion(w, -x, -y, -z);
|
||||
}
|
||||
|
||||
float getMagnitude() {
|
||||
return sqrt(w*w + x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
float m = getMagnitude();
|
||||
w /= m;
|
||||
x /= m;
|
||||
y /= m;
|
||||
z /= m;
|
||||
}
|
||||
|
||||
Quaternion getNormalized() {
|
||||
Quaternion r(w, x, y, z);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
class VectorInt16 {
|
||||
public:
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
|
||||
VectorInt16() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
VectorInt16(int16_t nx, int16_t ny, int16_t nz) {
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
float getMagnitude() {
|
||||
return sqrt(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
float m = getMagnitude();
|
||||
x /= m;
|
||||
y /= m;
|
||||
z /= m;
|
||||
}
|
||||
|
||||
VectorInt16 getNormalized() {
|
||||
VectorInt16 r(x, y, z);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
|
||||
void rotate(Quaternion *q) {
|
||||
// http://www.cprogramming.com/tutorial/3d/quaternions.html
|
||||
// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/index.htm
|
||||
// http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation
|
||||
// ^ or: http://webcache.googleusercontent.com/search?q=cache:xgJAp3bDNhQJ:content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation&hl=en&gl=us&strip=1
|
||||
|
||||
// P_out = q * P_in * conj(q)
|
||||
// - P_out is the output vector
|
||||
// - q is the orientation quaternion
|
||||
// - P_in is the input vector (a*aReal)
|
||||
// - conj(q) is the conjugate of the orientation quaternion (q=[w,x,y,z], q*=[w,-x,-y,-z])
|
||||
Quaternion p(0, x, y, z);
|
||||
|
||||
// quaternion multiplication: q * p, stored back in p
|
||||
p = q -> getProduct(p);
|
||||
|
||||
// quaternion multiplication: p * conj(q), stored back in p
|
||||
p = p.getProduct(q -> getConjugate());
|
||||
|
||||
// p quaternion is now [0, x', y', z']
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
}
|
||||
|
||||
VectorInt16 getRotated(Quaternion *q) {
|
||||
VectorInt16 r(x, y, z);
|
||||
r.rotate(q);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
class VectorFloat {
|
||||
public:
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
VectorFloat() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
}
|
||||
|
||||
VectorFloat(float nx, float ny, float nz) {
|
||||
x = nx;
|
||||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
float getMagnitude() {
|
||||
return sqrt(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
float m = getMagnitude();
|
||||
x /= m;
|
||||
y /= m;
|
||||
z /= m;
|
||||
}
|
||||
|
||||
VectorFloat getNormalized() {
|
||||
VectorFloat r(x, y, z);
|
||||
r.normalize();
|
||||
return r;
|
||||
}
|
||||
|
||||
void rotate(Quaternion *q) {
|
||||
Quaternion p(0, x, y, z);
|
||||
|
||||
// quaternion multiplication: q * p, stored back in p
|
||||
p = q -> getProduct(p);
|
||||
|
||||
// quaternion multiplication: p * conj(q), stored back in p
|
||||
p = p.getProduct(q -> getConjugate());
|
||||
|
||||
// p quaternion is now [0, x', y', z']
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
}
|
||||
|
||||
VectorFloat getRotated(Quaternion *q) {
|
||||
VectorFloat r(x, y, z);
|
||||
r.rotate(q);
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _HELPER_3DMATH_H_ */
|
||||
557
digistump-sam/libraries/OneWire/OneWire.cpp
Normal file
557
digistump-sam/libraries/OneWire/OneWire.cpp
Normal file
@@ -0,0 +1,557 @@
|
||||
/*
|
||||
Copyright (c) 2007, Jim Studt (original old version - many contributors since)
|
||||
|
||||
The latest version of this library may be found at:
|
||||
http://www.pjrc.com/teensy/td_libs_OneWire.html
|
||||
|
||||
OneWire has been maintained by Paul Stoffregen (paul@pjrc.com) since
|
||||
January 2010. At the time, it was in need of many bug fixes, but had
|
||||
been abandoned the original author (Jim Studt). None of the known
|
||||
contributors were interested in maintaining OneWire. Paul typically
|
||||
works on OneWire every 6 to 12 months. Patches usually wait that
|
||||
long. If anyone is interested in more actively maintaining OneWire,
|
||||
please contact Paul.
|
||||
|
||||
Version 2.2:
|
||||
Teensy 3.0 compatibility, Paul Stoffregen, paul@pjrc.com
|
||||
Arduino Due compatibility, http://arduino.cc/forum/index.php?topic=141030
|
||||
Fix DS18B20 example negative temperature
|
||||
Fix DS18B20 example's low res modes, Ken Butcher
|
||||
Improve reset timing, Mark Tillotson
|
||||
Add const qualifiers, Bertrik Sikken
|
||||
Add initial value input to crc16, Bertrik Sikken
|
||||
Add target_search() function, Scott Roberts
|
||||
|
||||
Version 2.1:
|
||||
Arduino 1.0 compatibility, Paul Stoffregen
|
||||
Improve temperature example, Paul Stoffregen
|
||||
DS250x_PROM example, Guillermo Lovato
|
||||
PIC32 (chipKit) compatibility, Jason Dangel, dangel.jason AT gmail.com
|
||||
Improvements from Glenn Trewitt:
|
||||
- crc16() now works
|
||||
- check_crc16() does all of calculation/checking work.
|
||||
- Added read_bytes() and write_bytes(), to reduce tedious loops.
|
||||
- Added ds2408 example.
|
||||
Delete very old, out-of-date readme file (info is here)
|
||||
|
||||
Version 2.0: Modifications by Paul Stoffregen, January 2010:
|
||||
http://www.pjrc.com/teensy/td_libs_OneWire.html
|
||||
Search fix from Robin James
|
||||
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238032295/27#27
|
||||
Use direct optimized I/O in all cases
|
||||
Disable interrupts during timing critical sections
|
||||
(this solves many random communication errors)
|
||||
Disable interrupts during read-modify-write I/O
|
||||
Reduce RAM consumption by eliminating unnecessary
|
||||
variables and trimming many to 8 bits
|
||||
Optimize both crc8 - table version moved to flash
|
||||
|
||||
Modified to work with larger numbers of devices - avoids loop.
|
||||
Tested in Arduino 11 alpha with 12 sensors.
|
||||
26 Sept 2008 -- Robin James
|
||||
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238032295/27#27
|
||||
|
||||
Updated to work with arduino-0008 and to include skip() as of
|
||||
2007/07/06. --RJL20
|
||||
|
||||
Modified to calculate the 8-bit CRC directly, avoiding the need for
|
||||
the 256-byte lookup table to be loaded in RAM. Tested in arduino-0010
|
||||
-- Tom Pollard, Jan 23, 2008
|
||||
|
||||
Jim Studt's original library was modified by Josh Larios.
|
||||
|
||||
Tom Pollard, pollard@alum.mit.edu, contributed around May 20, 2008
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Much of the code was inspired by Derek Yerger's code, though I don't
|
||||
think much of that remains. In any event that was..
|
||||
(copyleft) 2006 by Derek Yerger - Free to distribute freely.
|
||||
|
||||
The CRC code was excerpted and inspired by the Dallas Semiconductor
|
||||
sample code bearing this copyright.
|
||||
//---------------------------------------------------------------------------
|
||||
// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
|
||||
// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// Except as contained in this notice, the name of Dallas Semiconductor
|
||||
// shall not be used except as stated in the Dallas Semiconductor
|
||||
// Branding Policy.
|
||||
//--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "OneWire.h"
|
||||
|
||||
|
||||
OneWire::OneWire(uint8_t pin)
|
||||
{
|
||||
pinMode(pin, INPUT);
|
||||
bitmask = PIN_TO_BITMASK(pin);
|
||||
baseReg = PIN_TO_BASEREG(pin);
|
||||
#if ONEWIRE_SEARCH
|
||||
reset_search();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Perform the onewire reset function. We will wait up to 250uS for
|
||||
// the bus to come high, if it doesn't then it is broken or shorted
|
||||
// and we return a 0;
|
||||
//
|
||||
// Returns 1 if a device asserted a presence pulse, 0 otherwise.
|
||||
//
|
||||
uint8_t OneWire::reset(void)
|
||||
{
|
||||
IO_REG_TYPE mask = bitmask;
|
||||
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
|
||||
uint8_t r;
|
||||
uint8_t retries = 125;
|
||||
|
||||
noInterrupts();
|
||||
DIRECT_MODE_INPUT(reg, mask);
|
||||
interrupts();
|
||||
// wait until the wire is high... just in case
|
||||
do {
|
||||
if (--retries == 0) return 0;
|
||||
delayMicroseconds(2);
|
||||
} while ( !DIRECT_READ(reg, mask));
|
||||
|
||||
noInterrupts();
|
||||
DIRECT_WRITE_LOW(reg, mask);
|
||||
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
|
||||
interrupts();
|
||||
delayMicroseconds(480);
|
||||
noInterrupts();
|
||||
DIRECT_MODE_INPUT(reg, mask); // allow it to float
|
||||
delayMicroseconds(70);
|
||||
r = !DIRECT_READ(reg, mask);
|
||||
interrupts();
|
||||
delayMicroseconds(410);
|
||||
return r;
|
||||
}
|
||||
|
||||
//
|
||||
// Write a bit. Port and bit is used to cut lookup time and provide
|
||||
// more certain timing.
|
||||
//
|
||||
void OneWire::write_bit(uint8_t v)
|
||||
{
|
||||
IO_REG_TYPE mask=bitmask;
|
||||
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
|
||||
|
||||
if (v & 1) {
|
||||
noInterrupts();
|
||||
DIRECT_WRITE_LOW(reg, mask);
|
||||
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
|
||||
delayMicroseconds(10);
|
||||
DIRECT_WRITE_HIGH(reg, mask); // drive output high
|
||||
interrupts();
|
||||
delayMicroseconds(55);
|
||||
} else {
|
||||
noInterrupts();
|
||||
DIRECT_WRITE_LOW(reg, mask);
|
||||
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
|
||||
delayMicroseconds(65);
|
||||
DIRECT_WRITE_HIGH(reg, mask); // drive output high
|
||||
interrupts();
|
||||
delayMicroseconds(5);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Read a bit. Port and bit is used to cut lookup time and provide
|
||||
// more certain timing.
|
||||
//
|
||||
uint8_t OneWire::read_bit(void)
|
||||
{
|
||||
IO_REG_TYPE mask=bitmask;
|
||||
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
|
||||
uint8_t r;
|
||||
|
||||
noInterrupts();
|
||||
DIRECT_MODE_OUTPUT(reg, mask);
|
||||
DIRECT_WRITE_LOW(reg, mask);
|
||||
delayMicroseconds(3);
|
||||
DIRECT_MODE_INPUT(reg, mask); // let pin float, pull up will raise
|
||||
delayMicroseconds(10);
|
||||
r = DIRECT_READ(reg, mask);
|
||||
interrupts();
|
||||
delayMicroseconds(53);
|
||||
return r;
|
||||
}
|
||||
|
||||
//
|
||||
// Write a byte. The writing code uses the active drivers to raise the
|
||||
// pin high, if you need power after the write (e.g. DS18S20 in
|
||||
// parasite power mode) then set 'power' to 1, otherwise the pin will
|
||||
// go tri-state at the end of the write to avoid heating in a short or
|
||||
// other mishap.
|
||||
//
|
||||
void OneWire::write(uint8_t v, uint8_t power /* = 0 */) {
|
||||
uint8_t bitMask;
|
||||
|
||||
for (bitMask = 0x01; bitMask; bitMask <<= 1) {
|
||||
OneWire::write_bit( (bitMask & v)?1:0);
|
||||
}
|
||||
if ( !power) {
|
||||
noInterrupts();
|
||||
DIRECT_MODE_INPUT(baseReg, bitmask);
|
||||
DIRECT_WRITE_LOW(baseReg, bitmask);
|
||||
interrupts();
|
||||
}
|
||||
}
|
||||
|
||||
void OneWire::write_bytes(const uint8_t *buf, uint16_t count, bool power /* = 0 */) {
|
||||
for (uint16_t i = 0 ; i < count ; i++)
|
||||
write(buf[i]);
|
||||
if (!power) {
|
||||
noInterrupts();
|
||||
DIRECT_MODE_INPUT(baseReg, bitmask);
|
||||
DIRECT_WRITE_LOW(baseReg, bitmask);
|
||||
interrupts();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Read a byte
|
||||
//
|
||||
uint8_t OneWire::read() {
|
||||
uint8_t bitMask;
|
||||
uint8_t r = 0;
|
||||
|
||||
for (bitMask = 0x01; bitMask; bitMask <<= 1) {
|
||||
if ( OneWire::read_bit()) r |= bitMask;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void OneWire::read_bytes(uint8_t *buf, uint16_t count) {
|
||||
for (uint16_t i = 0 ; i < count ; i++)
|
||||
buf[i] = read();
|
||||
}
|
||||
|
||||
//
|
||||
// Do a ROM select
|
||||
//
|
||||
void OneWire::select(const uint8_t rom[8])
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
write(0x55); // Choose ROM
|
||||
|
||||
for (i = 0; i < 8; i++) write(rom[i]);
|
||||
}
|
||||
|
||||
//
|
||||
// Do a ROM skip
|
||||
//
|
||||
void OneWire::skip()
|
||||
{
|
||||
write(0xCC); // Skip ROM
|
||||
}
|
||||
|
||||
void OneWire::depower()
|
||||
{
|
||||
noInterrupts();
|
||||
DIRECT_MODE_INPUT(baseReg, bitmask);
|
||||
interrupts();
|
||||
}
|
||||
|
||||
#if ONEWIRE_SEARCH
|
||||
|
||||
//
|
||||
// You need to use this function to start a search again from the beginning.
|
||||
// You do not need to do it for the first search, though you could.
|
||||
//
|
||||
void OneWire::reset_search()
|
||||
{
|
||||
// reset the search state
|
||||
LastDiscrepancy = 0;
|
||||
LastDeviceFlag = FALSE;
|
||||
LastFamilyDiscrepancy = 0;
|
||||
for(int i = 7; ; i--) {
|
||||
ROM_NO[i] = 0;
|
||||
if ( i == 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the search to find the device type 'family_code' on the next call
|
||||
// to search(*newAddr) if it is present.
|
||||
//
|
||||
void OneWire::target_search(uint8_t family_code)
|
||||
{
|
||||
// set the search state to find SearchFamily type devices
|
||||
ROM_NO[0] = family_code;
|
||||
for (uint8_t i = 1; i < 8; i++)
|
||||
ROM_NO[i] = 0;
|
||||
LastDiscrepancy = 64;
|
||||
LastFamilyDiscrepancy = 0;
|
||||
LastDeviceFlag = FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Perform a search. If this function returns a '1' then it has
|
||||
// enumerated the next device and you may retrieve the ROM from the
|
||||
// OneWire::address variable. If there are no devices, no further
|
||||
// devices, or something horrible happens in the middle of the
|
||||
// enumeration then a 0 is returned. If a new device is found then
|
||||
// its address is copied to newAddr. Use OneWire::reset_search() to
|
||||
// start over.
|
||||
//
|
||||
// --- Replaced by the one from the Dallas Semiconductor web site ---
|
||||
//--------------------------------------------------------------------------
|
||||
// Perform the 1-Wire Search Algorithm on the 1-Wire bus using the existing
|
||||
// search state.
|
||||
// Return TRUE : device found, ROM number in ROM_NO buffer
|
||||
// FALSE : device not found, end of search
|
||||
//
|
||||
uint8_t OneWire::search(uint8_t *newAddr)
|
||||
{
|
||||
uint8_t id_bit_number;
|
||||
uint8_t last_zero, rom_byte_number, search_result;
|
||||
uint8_t id_bit, cmp_id_bit;
|
||||
|
||||
unsigned char rom_byte_mask, search_direction;
|
||||
|
||||
// initialize for search
|
||||
id_bit_number = 1;
|
||||
last_zero = 0;
|
||||
rom_byte_number = 0;
|
||||
rom_byte_mask = 1;
|
||||
search_result = 0;
|
||||
|
||||
// if the last call was not the last one
|
||||
if (!LastDeviceFlag)
|
||||
{
|
||||
// 1-Wire reset
|
||||
if (!reset())
|
||||
{
|
||||
// reset the search
|
||||
LastDiscrepancy = 0;
|
||||
LastDeviceFlag = FALSE;
|
||||
LastFamilyDiscrepancy = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// issue the search command
|
||||
write(0xF0);
|
||||
|
||||
// loop to do the search
|
||||
do
|
||||
{
|
||||
// read a bit and its complement
|
||||
id_bit = read_bit();
|
||||
cmp_id_bit = read_bit();
|
||||
|
||||
// check for no devices on 1-wire
|
||||
if ((id_bit == 1) && (cmp_id_bit == 1))
|
||||
break;
|
||||
else
|
||||
{
|
||||
// all devices coupled have 0 or 1
|
||||
if (id_bit != cmp_id_bit)
|
||||
search_direction = id_bit; // bit write value for search
|
||||
else
|
||||
{
|
||||
// if this discrepancy if before the Last Discrepancy
|
||||
// on a previous next then pick the same as last time
|
||||
if (id_bit_number < LastDiscrepancy)
|
||||
search_direction = ((ROM_NO[rom_byte_number] & rom_byte_mask) > 0);
|
||||
else
|
||||
// if equal to last pick 1, if not then pick 0
|
||||
search_direction = (id_bit_number == LastDiscrepancy);
|
||||
|
||||
// if 0 was picked then record its position in LastZero
|
||||
if (search_direction == 0)
|
||||
{
|
||||
last_zero = id_bit_number;
|
||||
|
||||
// check for Last discrepancy in family
|
||||
if (last_zero < 9)
|
||||
LastFamilyDiscrepancy = last_zero;
|
||||
}
|
||||
}
|
||||
|
||||
// set or clear the bit in the ROM byte rom_byte_number
|
||||
// with mask rom_byte_mask
|
||||
if (search_direction == 1)
|
||||
ROM_NO[rom_byte_number] |= rom_byte_mask;
|
||||
else
|
||||
ROM_NO[rom_byte_number] &= ~rom_byte_mask;
|
||||
|
||||
// serial number search direction write bit
|
||||
write_bit(search_direction);
|
||||
|
||||
// increment the byte counter id_bit_number
|
||||
// and shift the mask rom_byte_mask
|
||||
id_bit_number++;
|
||||
rom_byte_mask <<= 1;
|
||||
|
||||
// if the mask is 0 then go to new SerialNum byte rom_byte_number and reset mask
|
||||
if (rom_byte_mask == 0)
|
||||
{
|
||||
rom_byte_number++;
|
||||
rom_byte_mask = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
while(rom_byte_number < 8); // loop until through all ROM bytes 0-7
|
||||
|
||||
// if the search was successful then
|
||||
if (!(id_bit_number < 65))
|
||||
{
|
||||
// search successful so set LastDiscrepancy,LastDeviceFlag,search_result
|
||||
LastDiscrepancy = last_zero;
|
||||
|
||||
// check for last device
|
||||
if (LastDiscrepancy == 0)
|
||||
LastDeviceFlag = TRUE;
|
||||
|
||||
search_result = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// if no device found then reset counters so next 'search' will be like a first
|
||||
if (!search_result || !ROM_NO[0])
|
||||
{
|
||||
LastDiscrepancy = 0;
|
||||
LastDeviceFlag = FALSE;
|
||||
LastFamilyDiscrepancy = 0;
|
||||
search_result = FALSE;
|
||||
}
|
||||
for (int i = 0; i < 8; i++) newAddr[i] = ROM_NO[i];
|
||||
return search_result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if ONEWIRE_CRC
|
||||
// The 1-Wire CRC scheme is described in Maxim Application Note 27:
|
||||
// "Understanding and Using Cyclic Redundancy Checks with Maxim iButton Products"
|
||||
//
|
||||
|
||||
#if ONEWIRE_CRC8_TABLE
|
||||
// This table comes from Dallas sample code where it is freely reusable,
|
||||
// though Copyright (C) 2000 Dallas Semiconductor Corporation
|
||||
static const uint8_t PROGMEM dscrc_table[] = {
|
||||
0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,
|
||||
157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220,
|
||||
35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98,
|
||||
190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,
|
||||
70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7,
|
||||
219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154,
|
||||
101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36,
|
||||
248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185,
|
||||
140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,
|
||||
17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,
|
||||
175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,
|
||||
50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,
|
||||
202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139,
|
||||
87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,
|
||||
233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,
|
||||
116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};
|
||||
|
||||
//
|
||||
// Compute a Dallas Semiconductor 8 bit CRC. These show up in the ROM
|
||||
// and the registers. (note: this might better be done without to
|
||||
// table, it would probably be smaller and certainly fast enough
|
||||
// compared to all those delayMicrosecond() calls. But I got
|
||||
// confused, so I use this table from the examples.)
|
||||
//
|
||||
uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len)
|
||||
{
|
||||
uint8_t crc = 0;
|
||||
|
||||
while (len--) {
|
||||
crc = pgm_read_byte(dscrc_table + (crc ^ *addr++));
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Compute a Dallas Semiconductor 8 bit CRC directly.
|
||||
// this is much slower, but much smaller, than the lookup table.
|
||||
//
|
||||
uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len)
|
||||
{
|
||||
uint8_t crc = 0;
|
||||
|
||||
while (len--) {
|
||||
uint8_t inbyte = *addr++;
|
||||
for (uint8_t i = 8; i; i--) {
|
||||
uint8_t mix = (crc ^ inbyte) & 0x01;
|
||||
crc >>= 1;
|
||||
if (mix) crc ^= 0x8C;
|
||||
inbyte >>= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ONEWIRE_CRC16
|
||||
bool OneWire::check_crc16(const uint8_t* input, uint16_t len, const uint8_t* inverted_crc, uint16_t crc)
|
||||
{
|
||||
crc = ~crc16(input, len, crc);
|
||||
return (crc & 0xFF) == inverted_crc[0] && (crc >> 8) == inverted_crc[1];
|
||||
}
|
||||
|
||||
uint16_t OneWire::crc16(const uint8_t* input, uint16_t len, uint16_t crc)
|
||||
{
|
||||
static const uint8_t oddparity[16] =
|
||||
{ 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
|
||||
|
||||
for (uint16_t i = 0 ; i < len ; i++) {
|
||||
// Even though we're just copying a byte from the input,
|
||||
// we'll be doing 16-bit computation with it.
|
||||
uint16_t cdata = input[i];
|
||||
cdata = (cdata ^ crc) & 0xff;
|
||||
crc >>= 8;
|
||||
|
||||
if (oddparity[cdata & 0x0F] ^ oddparity[cdata >> 4])
|
||||
crc ^= 0xC001;
|
||||
|
||||
cdata <<= 6;
|
||||
crc ^= cdata;
|
||||
cdata <<= 1;
|
||||
crc ^= cdata;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
229
digistump-sam/libraries/OneWire/OneWire.h
Normal file
229
digistump-sam/libraries/OneWire/OneWire.h
Normal file
@@ -0,0 +1,229 @@
|
||||
#ifndef OneWire_h
|
||||
#define OneWire_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h" // for delayMicroseconds, digitalPinToBitMask, etc
|
||||
#else
|
||||
#include "WProgram.h" // for delayMicroseconds
|
||||
#include "pins_arduino.h" // for digitalPinToBitMask, etc
|
||||
#endif
|
||||
|
||||
// You can exclude certain features from OneWire. In theory, this
|
||||
// might save some space. In practice, the compiler automatically
|
||||
// removes unused code (technically, the linker, using -fdata-sections
|
||||
// and -ffunction-sections when compiling, and Wl,--gc-sections
|
||||
// when linking), so most of these will not result in any code size
|
||||
// reduction. Well, unless you try to use the missing features
|
||||
// and redesign your program to not need them! ONEWIRE_CRC8_TABLE
|
||||
// is the exception, because it selects a fast but large algorithm
|
||||
// or a small but slow algorithm.
|
||||
|
||||
// you can exclude onewire_search by defining that to 0
|
||||
#ifndef ONEWIRE_SEARCH
|
||||
#define ONEWIRE_SEARCH 1
|
||||
#endif
|
||||
|
||||
// You can exclude CRC checks altogether by defining this to 0
|
||||
#ifndef ONEWIRE_CRC
|
||||
#define ONEWIRE_CRC 1
|
||||
#endif
|
||||
|
||||
// Select the table-lookup method of computing the 8-bit CRC
|
||||
// by setting this to 1. The lookup table enlarges code size by
|
||||
// about 250 bytes. It does NOT consume RAM (but did in very
|
||||
// old versions of OneWire). If you disable this, a slower
|
||||
// but very compact algorithm is used.
|
||||
#ifndef ONEWIRE_CRC8_TABLE
|
||||
#define ONEWIRE_CRC8_TABLE 1
|
||||
#endif
|
||||
|
||||
// You can allow 16-bit CRC checks by defining this to 1
|
||||
// (Note that ONEWIRE_CRC must also be 1.)
|
||||
#ifndef ONEWIRE_CRC16
|
||||
#define ONEWIRE_CRC16 1
|
||||
#endif
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
// Platform specific I/O definitions
|
||||
|
||||
#if defined(__AVR__)
|
||||
#define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin)))
|
||||
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
|
||||
#define IO_REG_TYPE uint8_t
|
||||
#define IO_REG_ASM asm("r30")
|
||||
#define DIRECT_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)
|
||||
#define DIRECT_MODE_INPUT(base, mask) ((*((base)+1)) &= ~(mask))
|
||||
#define DIRECT_MODE_OUTPUT(base, mask) ((*((base)+1)) |= (mask))
|
||||
#define DIRECT_WRITE_LOW(base, mask) ((*((base)+2)) &= ~(mask))
|
||||
#define DIRECT_WRITE_HIGH(base, mask) ((*((base)+2)) |= (mask))
|
||||
|
||||
#elif defined(__MK20DX128__)
|
||||
#define PIN_TO_BASEREG(pin) (portOutputRegister(pin))
|
||||
#define PIN_TO_BITMASK(pin) (1)
|
||||
#define IO_REG_TYPE uint8_t
|
||||
#define IO_REG_ASM
|
||||
#define DIRECT_READ(base, mask) (*((base)+512))
|
||||
#define DIRECT_MODE_INPUT(base, mask) (*((base)+640) = 0)
|
||||
#define DIRECT_MODE_OUTPUT(base, mask) (*((base)+640) = 1)
|
||||
#define DIRECT_WRITE_LOW(base, mask) (*((base)+256) = 1)
|
||||
#define DIRECT_WRITE_HIGH(base, mask) (*((base)+128) = 1)
|
||||
|
||||
#elif defined(__SAM3X8E__)
|
||||
// Arduino 1.5.1 may have a bug in delayMicroseconds() on Arduino Due.
|
||||
// http://arduino.cc/forum/index.php/topic,141030.msg1076268.html#msg1076268
|
||||
// If you have trouble with OneWire on Arduino Due, please check the
|
||||
// status of delayMicroseconds() before reporting a bug in OneWire!
|
||||
#define PIN_TO_BASEREG(pin) (&(digitalPinToPort(pin)->PIO_PER))
|
||||
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
|
||||
#define IO_REG_TYPE uint32_t
|
||||
#define IO_REG_ASM
|
||||
#define DIRECT_READ(base, mask) (((*((base)+15)) & (mask)) ? 1 : 0)
|
||||
#define DIRECT_MODE_INPUT(base, mask) ((*((base)+5)) = (mask))
|
||||
#define DIRECT_MODE_OUTPUT(base, mask) ((*((base)+4)) = (mask))
|
||||
#define DIRECT_WRITE_LOW(base, mask) ((*((base)+13)) = (mask))
|
||||
#define DIRECT_WRITE_HIGH(base, mask) ((*((base)+12)) = (mask))
|
||||
#ifndef PROGMEM
|
||||
#define PROGMEM
|
||||
#endif
|
||||
#ifndef pgm_read_byte
|
||||
#define pgm_read_byte(addr) (*(const uint8_t *)(addr))
|
||||
#endif
|
||||
|
||||
#elif defined(__PIC32MX__)
|
||||
#define PIN_TO_BASEREG(pin) (portModeRegister(digitalPinToPort(pin)))
|
||||
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
|
||||
#define IO_REG_TYPE uint32_t
|
||||
#define IO_REG_ASM
|
||||
#define DIRECT_READ(base, mask) (((*(base+4)) & (mask)) ? 1 : 0) //PORTX + 0x10
|
||||
#define DIRECT_MODE_INPUT(base, mask) ((*(base+2)) = (mask)) //TRISXSET + 0x08
|
||||
#define DIRECT_MODE_OUTPUT(base, mask) ((*(base+1)) = (mask)) //TRISXCLR + 0x04
|
||||
#define DIRECT_WRITE_LOW(base, mask) ((*(base+8+1)) = (mask)) //LATXCLR + 0x24
|
||||
#define DIRECT_WRITE_HIGH(base, mask) ((*(base+8+2)) = (mask)) //LATXSET + 0x28
|
||||
|
||||
#else
|
||||
#error "Please define I/O register types here"
|
||||
#endif
|
||||
|
||||
|
||||
class OneWire
|
||||
{
|
||||
private:
|
||||
IO_REG_TYPE bitmask;
|
||||
volatile IO_REG_TYPE *baseReg;
|
||||
|
||||
#if ONEWIRE_SEARCH
|
||||
// global search state
|
||||
unsigned char ROM_NO[8];
|
||||
uint8_t LastDiscrepancy;
|
||||
uint8_t LastFamilyDiscrepancy;
|
||||
uint8_t LastDeviceFlag;
|
||||
#endif
|
||||
|
||||
public:
|
||||
OneWire( uint8_t pin);
|
||||
|
||||
// Perform a 1-Wire reset cycle. Returns 1 if a device responds
|
||||
// with a presence pulse. Returns 0 if there is no device or the
|
||||
// bus is shorted or otherwise held low for more than 250uS
|
||||
uint8_t reset(void);
|
||||
|
||||
// Issue a 1-Wire rom select command, you do the reset first.
|
||||
void select(const uint8_t rom[8]);
|
||||
|
||||
// Issue a 1-Wire rom skip command, to address all on bus.
|
||||
void skip(void);
|
||||
|
||||
// Write a byte. If 'power' is one then the wire is held high at
|
||||
// the end for parasitically powered devices. You are responsible
|
||||
// for eventually depowering it by calling depower() or doing
|
||||
// another read or write.
|
||||
void write(uint8_t v, uint8_t power = 0);
|
||||
|
||||
void write_bytes(const uint8_t *buf, uint16_t count, bool power = 0);
|
||||
|
||||
// Read a byte.
|
||||
uint8_t read(void);
|
||||
|
||||
void read_bytes(uint8_t *buf, uint16_t count);
|
||||
|
||||
// Write a bit. The bus is always left powered at the end, see
|
||||
// note in write() about that.
|
||||
void write_bit(uint8_t v);
|
||||
|
||||
// Read a bit.
|
||||
uint8_t read_bit(void);
|
||||
|
||||
// Stop forcing power onto the bus. You only need to do this if
|
||||
// you used the 'power' flag to write() or used a write_bit() call
|
||||
// and aren't about to do another read or write. You would rather
|
||||
// not leave this powered if you don't have to, just in case
|
||||
// someone shorts your bus.
|
||||
void depower(void);
|
||||
|
||||
#if ONEWIRE_SEARCH
|
||||
// Clear the search state so that if will start from the beginning again.
|
||||
void reset_search();
|
||||
|
||||
// Setup the search to find the device type 'family_code' on the next call
|
||||
// to search(*newAddr) if it is present.
|
||||
void target_search(uint8_t family_code);
|
||||
|
||||
// Look for the next device. Returns 1 if a new address has been
|
||||
// returned. A zero might mean that the bus is shorted, there are
|
||||
// no devices, or you have already retrieved all of them. It
|
||||
// might be a good idea to check the CRC to make sure you didn't
|
||||
// get garbage. The order is deterministic. You will always get
|
||||
// the same devices in the same order.
|
||||
uint8_t search(uint8_t *newAddr);
|
||||
#endif
|
||||
|
||||
#if ONEWIRE_CRC
|
||||
// Compute a Dallas Semiconductor 8 bit CRC, these are used in the
|
||||
// ROM and scratchpad registers.
|
||||
static uint8_t crc8(const uint8_t *addr, uint8_t len);
|
||||
|
||||
#if ONEWIRE_CRC16
|
||||
// Compute the 1-Wire CRC16 and compare it against the received CRC.
|
||||
// Example usage (reading a DS2408):
|
||||
// // Put everything in a buffer so we can compute the CRC easily.
|
||||
// uint8_t buf[13];
|
||||
// buf[0] = 0xF0; // Read PIO Registers
|
||||
// buf[1] = 0x88; // LSB address
|
||||
// buf[2] = 0x00; // MSB address
|
||||
// WriteBytes(net, buf, 3); // Write 3 cmd bytes
|
||||
// ReadBytes(net, buf+3, 10); // Read 6 data bytes, 2 0xFF, 2 CRC16
|
||||
// if (!CheckCRC16(buf, 11, &buf[11])) {
|
||||
// // Handle error.
|
||||
// }
|
||||
//
|
||||
// @param input - Array of bytes to checksum.
|
||||
// @param len - How many bytes to use.
|
||||
// @param inverted_crc - The two CRC16 bytes in the received data.
|
||||
// This should just point into the received data,
|
||||
// *not* at a 16-bit integer.
|
||||
// @param crc - The crc starting value (optional)
|
||||
// @return True, iff the CRC matches.
|
||||
static bool check_crc16(const uint8_t* input, uint16_t len, const uint8_t* inverted_crc, uint16_t crc = 0);
|
||||
|
||||
// Compute a Dallas Semiconductor 16 bit CRC. This is required to check
|
||||
// the integrity of data received from many 1-Wire devices. Note that the
|
||||
// CRC computed here is *not* what you'll get from the 1-Wire network,
|
||||
// for two reasons:
|
||||
// 1) The CRC is transmitted bitwise inverted.
|
||||
// 2) Depending on the endian-ness of your processor, the binary
|
||||
// representation of the two-byte return value may have a different
|
||||
// byte order than the two bytes you get from 1-Wire.
|
||||
// @param input - Array of bytes to checksum.
|
||||
// @param len - How many bytes to use.
|
||||
// @param crc - The crc starting value (optional)
|
||||
// @return The CRC16, as defined by Dallas Semiconductor.
|
||||
static uint16_t crc16(const uint8_t* input, uint16_t len, uint16_t crc = 0);
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,112 @@
|
||||
#include <OneWire.h>
|
||||
|
||||
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
|
||||
//
|
||||
// http://www.pjrc.com/teensy/td_libs_OneWire.html
|
||||
//
|
||||
// The DallasTemperature library can do all this work for you!
|
||||
// http://milesburton.com/Dallas_Temperature_Control_Library
|
||||
|
||||
OneWire ds(10); // on pin 10 (a 4.7K resistor is necessary)
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
byte i;
|
||||
byte present = 0;
|
||||
byte type_s;
|
||||
byte data[12];
|
||||
byte addr[8];
|
||||
float celsius, fahrenheit;
|
||||
|
||||
if ( !ds.search(addr)) {
|
||||
Serial.println("No more addresses.");
|
||||
Serial.println();
|
||||
ds.reset_search();
|
||||
delay(250);
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("ROM =");
|
||||
for( i = 0; i < 8; i++) {
|
||||
Serial.write(' ');
|
||||
Serial.print(addr[i], HEX);
|
||||
}
|
||||
|
||||
if (OneWire::crc8(addr, 7) != addr[7]) {
|
||||
Serial.println("CRC is not valid!");
|
||||
return;
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// the first ROM byte indicates which chip
|
||||
switch (addr[0]) {
|
||||
case 0x10:
|
||||
Serial.println(" Chip = DS18S20"); // or old DS1820
|
||||
type_s = 1;
|
||||
break;
|
||||
case 0x28:
|
||||
Serial.println(" Chip = DS18B20");
|
||||
type_s = 0;
|
||||
break;
|
||||
case 0x22:
|
||||
Serial.println(" Chip = DS1822");
|
||||
type_s = 0;
|
||||
break;
|
||||
default:
|
||||
Serial.println("Device is not a DS18x20 family device.");
|
||||
return;
|
||||
}
|
||||
|
||||
ds.reset();
|
||||
ds.select(addr);
|
||||
ds.write(0x44, 1); // start conversion, with parasite power on at the end
|
||||
|
||||
delay(1000); // maybe 750ms is enough, maybe not
|
||||
// we might do a ds.depower() here, but the reset will take care of it.
|
||||
|
||||
present = ds.reset();
|
||||
ds.select(addr);
|
||||
ds.write(0xBE); // Read Scratchpad
|
||||
|
||||
Serial.print(" Data = ");
|
||||
Serial.print(present, HEX);
|
||||
Serial.print(" ");
|
||||
for ( i = 0; i < 9; i++) { // we need 9 bytes
|
||||
data[i] = ds.read();
|
||||
Serial.print(data[i], HEX);
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.print(" CRC=");
|
||||
Serial.print(OneWire::crc8(data, 8), HEX);
|
||||
Serial.println();
|
||||
|
||||
// Convert the data to actual temperature
|
||||
// because the result is a 16 bit signed integer, it should
|
||||
// be stored to an "int16_t" type, which is always 16 bits
|
||||
// even when compiled on a 32 bit processor.
|
||||
int16_t raw = (data[1] << 8) | data[0];
|
||||
if (type_s) {
|
||||
raw = raw << 3; // 9 bit resolution default
|
||||
if (data[7] == 0x10) {
|
||||
// "count remain" gives full 12 bit resolution
|
||||
raw = (raw & 0xFFF0) + 12 - data[6];
|
||||
}
|
||||
} else {
|
||||
byte cfg = (data[4] & 0x60);
|
||||
// at lower res, the low bits are undefined, so let's zero them
|
||||
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
|
||||
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
|
||||
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
|
||||
//// default is 12 bit resolution, 750 ms conversion time
|
||||
}
|
||||
celsius = (float)raw / 16.0;
|
||||
fahrenheit = celsius * 1.8 + 32.0;
|
||||
Serial.print(" Temperature = ");
|
||||
Serial.print(celsius);
|
||||
Serial.print(" Celsius, ");
|
||||
Serial.print(fahrenheit);
|
||||
Serial.println(" Fahrenheit");
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#include <OneWire.h>
|
||||
|
||||
/*
|
||||
* DS2408 8-Channel Addressable Switch
|
||||
*
|
||||
* Writte by Glenn Trewitt, glenn at trewitt dot org
|
||||
*
|
||||
* Some notes about the DS2408:
|
||||
* - Unlike most input/output ports, the DS2408 doesn't have mode bits to
|
||||
* set whether the pins are input or output. If you issue a read command,
|
||||
* they're inputs. If you write to them, they're outputs.
|
||||
* - For reading from a switch, you should use 10K pull-up resisters.
|
||||
*/
|
||||
|
||||
void PrintBytes(uint8_t* addr, uint8_t count, bool newline=0) {
|
||||
for (uint8_t i = 0; i < count; i++) {
|
||||
Serial.print(addr[i]>>4, HEX);
|
||||
Serial.print(addr[i]&0x0f, HEX);
|
||||
}
|
||||
if (newline)
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void ReadAndReport(OneWire* net, uint8_t* addr) {
|
||||
Serial.print(" Reading DS2408 ");
|
||||
PrintBytes(addr, 8);
|
||||
Serial.println();
|
||||
|
||||
uint8_t buf[13]; // Put everything in the buffer so we can compute CRC easily.
|
||||
buf[0] = 0xF0; // Read PIO Registers
|
||||
buf[1] = 0x88; // LSB address
|
||||
buf[2] = 0x00; // MSB address
|
||||
net->write_bytes(buf, 3);
|
||||
net->read_bytes(buf+3, 10); // 3 cmd bytes, 6 data bytes, 2 0xFF, 2 CRC16
|
||||
net->reset();
|
||||
|
||||
if (!OneWire::check_crc16(buf, 11, &buf[11])) {
|
||||
Serial.print("CRC failure in DS2408 at ");
|
||||
PrintBytes(addr, 8, true);
|
||||
return;
|
||||
}
|
||||
Serial.print(" DS2408 data = ");
|
||||
// First 3 bytes contain command, register address.
|
||||
Serial.println(buf[3], BIN);
|
||||
}
|
||||
|
||||
OneWire net(10); // on pin 10
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
byte i;
|
||||
byte present = 0;
|
||||
byte addr[8];
|
||||
|
||||
if (!net.search(addr)) {
|
||||
Serial.print("No more addresses.\n");
|
||||
net.reset_search();
|
||||
delay(1000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OneWire::crc8(addr, 7) != addr[7]) {
|
||||
Serial.print("CRC is not valid!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (addr[0] != 0x29) {
|
||||
PrintBytes(addr, 8);
|
||||
Serial.print(" is not a DS2408.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ReadAndReport(&net, addr);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
DS250x add-only programmable memory reader w/SKIP ROM.
|
||||
|
||||
The DS250x is a 512/1024bit add-only PROM(you can add data but cannot change the old one) that's used mainly for device identification purposes
|
||||
like serial number, mfgr data, unique identifiers, etc. It uses the Maxim 1-wire bus.
|
||||
|
||||
This sketch will use the SKIP ROM function that skips the 1-Wire search phase since we only have one device connected in the bus on digital pin 6.
|
||||
If more than one device is connected to the bus, it will fail.
|
||||
Sketch will not verify if device connected is from the DS250x family since the skip rom function effectively skips the family-id byte readout.
|
||||
thus it is possible to run this sketch with any Maxim OneWire device in which case the command CRC will most likely fail.
|
||||
Sketch will only read the first page of memory(32bits) starting from the lower address(0000h), if more than 1 device is present, then use the sketch with search functions.
|
||||
Remember to put a 4.7K pullup resistor between pin 6 and +Vcc
|
||||
|
||||
To change the range or ammount of data to read, simply change the data array size, LSB/MSB addresses and for loop iterations
|
||||
|
||||
This example code is in the public domain and is provided AS-IS.
|
||||
|
||||
Built with Arduino 0022 and PJRC OneWire 2.0 library http://www.pjrc.com/teensy/td_libs_OneWire.html
|
||||
|
||||
created by Guillermo Lovato <glovato@gmail.com>
|
||||
march/2011
|
||||
|
||||
*/
|
||||
|
||||
#include <OneWire.h>
|
||||
OneWire ds(6); // OneWire bus on digital pin 6
|
||||
void setup() {
|
||||
Serial.begin (9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
byte i; // This is for the for loops
|
||||
boolean present; // device present var
|
||||
byte data[32]; // container for the data from device
|
||||
byte leemem[3] = { // array with the commands to initiate a read, DS250x devices expect 3 bytes to start a read: command,LSB&MSB adresses
|
||||
0xF0 , 0x00 , 0x00 }; // 0xF0 is the Read Data command, followed by 00h 00h as starting address(the beginning, 0000h)
|
||||
byte ccrc; // Variable to store the command CRC
|
||||
byte ccrc_calc;
|
||||
|
||||
present = ds.reset(); // OneWire bus reset, always needed to start operation on the bus, returns a 1/TRUE if there's a device present.
|
||||
ds.skip(); // Skip ROM search
|
||||
|
||||
if (present == TRUE){ // We only try to read the data if there's a device present
|
||||
Serial.println("DS250x device present");
|
||||
ds.write(leemem[0],1); // Read data command, leave ghost power on
|
||||
ds.write(leemem[1],1); // LSB starting address, leave ghost power on
|
||||
ds.write(leemem[2],1); // MSB starting address, leave ghost power on
|
||||
|
||||
ccrc = ds.read(); // DS250x generates a CRC for the command we sent, we assign a read slot and store it's value
|
||||
ccrc_calc = OneWire::crc8(leemem, 3); // We calculate the CRC of the commands we sent using the library function and store it
|
||||
|
||||
if ( ccrc_calc != ccrc) { // Then we compare it to the value the ds250x calculated, if it fails, we print debug messages and abort
|
||||
Serial.println("Invalid command CRC!");
|
||||
Serial.print("Calculated CRC:");
|
||||
Serial.println(ccrc_calc,HEX); // HEX makes it easier to observe and compare
|
||||
Serial.print("DS250x readback CRC:");
|
||||
Serial.println(ccrc,HEX);
|
||||
return; // Since CRC failed, we abort the rest of the loop and start over
|
||||
}
|
||||
Serial.println("Data is: "); // For the printout of the data
|
||||
for ( i = 0; i < 32; i++) { // Now it's time to read the PROM data itself, each page is 32 bytes so we need 32 read commands
|
||||
data[i] = ds.read(); // we store each read byte to a different position in the data array
|
||||
Serial.print(data[i]); // printout in ASCII
|
||||
Serial.print(" "); // blank space
|
||||
}
|
||||
Serial.println();
|
||||
delay(5000); // Delay so we don't saturate the serial output
|
||||
}
|
||||
else { // Nothing is connected in the bus
|
||||
Serial.println("Nothing connected");
|
||||
delay(3000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
|
||||
#include <OneWire.h>
|
||||
#include <DigiUSB.h>
|
||||
#define DS18S20_ID 0x10
|
||||
#define DS18B20_ID 0x28
|
||||
int temp;
|
||||
|
||||
|
||||
OneWire ds(5);
|
||||
|
||||
byte data[12];
|
||||
byte addr[8];
|
||||
|
||||
boolean readTemperature(){
|
||||
|
||||
|
||||
|
||||
//find a device
|
||||
|
||||
|
||||
if (!ds.search(addr)) {
|
||||
ds.reset_search();
|
||||
return false;
|
||||
}
|
||||
if (OneWire::crc8( addr, 7) != addr[7]) {
|
||||
return false;
|
||||
}
|
||||
if (addr[0] != DS18S20_ID && addr[0] != DS18B20_ID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ds.reset();
|
||||
ds.select(addr);
|
||||
// Start conversion
|
||||
ds.write(0x44, 1);
|
||||
// Wait some time...
|
||||
}
|
||||
|
||||
boolean getTemperature(){
|
||||
byte i;
|
||||
byte present = 0;
|
||||
present = ds.reset();
|
||||
ds.select(addr);
|
||||
// Issue Read scratchpad command
|
||||
ds.write(0xBE);
|
||||
// Receive 9 bytes
|
||||
for ( i = 0; i < 9; i++) {
|
||||
data[i] = ds.read();
|
||||
}
|
||||
// Calculate temperature value
|
||||
temp = ((( (data[1] << 8) + data[0] )*0.0625)*1.8)+32;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void setup(){
|
||||
DigiUSB.begin();
|
||||
DigiUSB.print("Start");
|
||||
}
|
||||
|
||||
|
||||
void loop(){
|
||||
|
||||
|
||||
readTemperature();
|
||||
DigiUSB.delay(1000);
|
||||
getTemperature();
|
||||
DigiUSB.println(temp);
|
||||
|
||||
DigiUSB.delay(1000);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
38
digistump-sam/libraries/OneWire/keywords.txt
Normal file
38
digistump-sam/libraries/OneWire/keywords.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For OneWire
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
OneWire KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
reset KEYWORD2
|
||||
write_bit KEYWORD2
|
||||
read_bit KEYWORD2
|
||||
write KEYWORD2
|
||||
write_bytes KEYWORD2
|
||||
read KEYWORD2
|
||||
read_bytes KEYWORD2
|
||||
select KEYWORD2
|
||||
skip KEYWORD2
|
||||
depower KEYWORD2
|
||||
reset_search KEYWORD2
|
||||
search KEYWORD2
|
||||
crc8 KEYWORD2
|
||||
crc16 KEYWORD2
|
||||
check_crc16 KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
14
digistump-sam/libraries/RF24/.gitignore
vendored
Normal file
14
digistump-sam/libraries/RF24/.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
*.bak
|
||||
*.o
|
||||
.*.swp
|
||||
*.orig
|
||||
.swp
|
||||
docs/
|
||||
output/
|
||||
ojam/
|
||||
out/
|
||||
16000000/
|
||||
8000000/
|
||||
out_native/
|
||||
version.h
|
||||
Session.vim
|
||||
1551
digistump-sam/libraries/RF24/Doxyfile
Normal file
1551
digistump-sam/libraries/RF24/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
53
digistump-sam/libraries/RF24/FAQ
Normal file
53
digistump-sam/libraries/RF24/FAQ
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @page FAQ Frequently Asked Questions
|
||||
*
|
||||
* @ref starting
|
||||
*
|
||||
* @ref hardware
|
||||
*
|
||||
* @ref range
|
||||
*
|
||||
* @ref issues
|
||||
*
|
||||
* @ref ram
|
||||
*
|
||||
* @ref tests
|
||||
*
|
||||
* @section starting Where do I start?
|
||||
*
|
||||
* See my blog post:
|
||||
* <a href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>
|
||||
*
|
||||
* @section hardware Where can I buy some hardware?
|
||||
*
|
||||
* @li iTeadStudio sells the basic <a href="http://iteadstudio.com/store/index.php?main_page=product_info&cPath=7&products_id=53">2.4G Wireless nRF24L01+ Module</a> for $4. Such a deal!
|
||||
* @li MDfly.com sells the same unit, <a href="http://www.mdfly.com/index.php?main_page=product_info&cPath=8_52&products_id=81">2.4Ghz Wireless nRF24L01+ Transceiver Module</a> for $6.95, but it ships from the US so it gets there a lot faster. Great place to get a few units and get started quickly.
|
||||
* @li MDfly.com also has the <a href="http://www.mdfly.com/index.php?main_page=product_info&cPath=8_52&products_id=433">nRF24L01 2.4GHz Transceiver Module w/ Power Amplifier</a> for $13.95, which increases range dramatically and uses a chip antenna
|
||||
* @li MDfly.com also has the <a href="http://www.mdfly.com/index.php?main_page=product_info&cPath=8_52&products_id=583">2.4GHz Transceiver Module w/ Power Amplifier</a> with an external antenna for $19.95
|
||||
*
|
||||
* @section range What is the range of these units?
|
||||
*
|
||||
* Here are some results from measurements I have taken, using the basic $4 iTeadStudio units.
|
||||
* I recommend that everyone take their own measurements in their particular circumstances.
|
||||
*
|
||||
* @li non-plus unit, 2MBps (worst case), 41+ ft line of sight indoors, immediate dropoff with any deviation from LOS. (41 ft is as far as I can go in my house without turning a corner)
|
||||
* @li Plus unit, 250kbps (best case), 46 ft around two corners indoors, 49 ft around one corner. More importantly, at 250k, packet loss is almost negligible through almost all of that range.
|
||||
* @li Both units at 1MBps, plus unit gets about 10% range improvement over non-plus in almost all situations.
|
||||
*
|
||||
* @section issues What should I do if I find a problem?
|
||||
*
|
||||
* Please <a href="https://github.com/maniacbug/RF24/issues/new">open an issue</a> on github if you find any problems using it with any version of Arduino or Maple.
|
||||
*
|
||||
* @section ram What is the RAM footprint of this library?
|
||||
*
|
||||
* 16 bytes. A single radio object consumes 16 bytes of RAM, and the library
|
||||
* does not use any other RAM statically.
|
||||
*
|
||||
* @section tests Why are the examples in the 'tests' directory failing?
|
||||
*
|
||||
* The sketches in the 'tests' directory are not for general use.
|
||||
* Please use the examples in the 'examples' directory instead.
|
||||
*
|
||||
* The 'tests' directory is only for people making changes to the library
|
||||
* to ensure that their changes do not break anything.
|
||||
*/
|
||||
20
digistump-sam/libraries/RF24/README.md
Normal file
20
digistump-sam/libraries/RF24/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Arduino driver for nRF24L01 2.4GHz Wireless Transceiver
|
||||
|
||||
Design Goals: This library is designed to be...
|
||||
|
||||
* Maximally compliant with the intended operation of the chip
|
||||
* Easy for beginners to use
|
||||
* Consumed with a public interface that's similiar to other Arduino standard libraries
|
||||
* Built against the standard SPI library.
|
||||
|
||||
Please refer to:
|
||||
|
||||
* [Documentation Main Page](http://maniacbug.github.com/RF24)
|
||||
* [RF24 Class Documentation](http://maniacbug.github.com/RF24/classRF24.html)
|
||||
* [Source Code](https://github.com/maniacbug/RF24)
|
||||
* [Downloads](https://github.com/maniacbug/RF24/archives/master)
|
||||
* [Chip Datasheet](http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf)
|
||||
|
||||
This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
|
||||
the SPI hardware will go into 'slave' mode.
|
||||
|
||||
985
digistump-sam/libraries/RF24/RF24.cpp
Normal file
985
digistump-sam/libraries/RF24/RF24.cpp
Normal file
@@ -0,0 +1,985 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24_config.h"
|
||||
#include "RF24.h"
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::csn(int mode)
|
||||
{
|
||||
// Minimum ideal SPI bus speed is 2x data rate
|
||||
// If we assume 2Mbs data rate and 16Mhz clock, a
|
||||
// divider of 4 is the minimum we want.
|
||||
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
|
||||
#ifdef ARDUINO
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
SPI.setDataMode(SPI_MODE0);
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV4);
|
||||
#endif
|
||||
digitalWrite(csn_pin,mode);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::ce(int level)
|
||||
{
|
||||
digitalWrite(ce_pin,level);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( R_REGISTER | ( REGISTER_MASK & reg ) );
|
||||
while ( len-- )
|
||||
*buf++ = SPI.transfer(0xff);
|
||||
|
||||
csn(HIGH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::read_register(uint8_t reg)
|
||||
{
|
||||
csn(LOW);
|
||||
SPI.transfer( R_REGISTER | ( REGISTER_MASK & reg ) );
|
||||
uint8_t result = SPI.transfer(0xff);
|
||||
|
||||
csn(HIGH);
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( W_REGISTER | ( REGISTER_MASK & reg ) );
|
||||
while ( len-- )
|
||||
SPI.transfer(*buf++);
|
||||
|
||||
csn(HIGH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::write_register(uint8_t reg, uint8_t value)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
IF_SERIAL_DEBUG(printf_P(PSTR("write_register(%02x,%02x)\r\n"),reg,value));
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( W_REGISTER | ( REGISTER_MASK & reg ) );
|
||||
SPI.transfer(value);
|
||||
csn(HIGH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::write_payload(const void* buf, uint8_t len)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
const uint8_t* current = reinterpret_cast<const uint8_t*>(buf);
|
||||
|
||||
uint8_t data_len = min(len,payload_size);
|
||||
uint8_t blank_len = dynamic_payloads_enabled ? 0 : payload_size - data_len;
|
||||
|
||||
//printf("[Writing %u bytes %u blanks]",data_len,blank_len);
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( W_TX_PAYLOAD );
|
||||
while ( data_len-- )
|
||||
SPI.transfer(*current++);
|
||||
while ( blank_len-- )
|
||||
SPI.transfer(0);
|
||||
csn(HIGH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::read_payload(void* buf, uint8_t len)
|
||||
{
|
||||
uint8_t status;
|
||||
uint8_t* current = reinterpret_cast<uint8_t*>(buf);
|
||||
|
||||
uint8_t data_len = min(len,payload_size);
|
||||
uint8_t blank_len = dynamic_payloads_enabled ? 0 : payload_size - data_len;
|
||||
|
||||
//printf("[Reading %u bytes %u blanks]",data_len,blank_len);
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( R_RX_PAYLOAD );
|
||||
while ( data_len-- )
|
||||
*current++ = SPI.transfer(0xff);
|
||||
while ( blank_len-- )
|
||||
SPI.transfer(0xff);
|
||||
csn(HIGH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::flush_rx(void)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( FLUSH_RX );
|
||||
csn(HIGH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::flush_tx(void)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( FLUSH_TX );
|
||||
csn(HIGH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::get_status(void)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
csn(LOW);
|
||||
status = SPI.transfer( NOP );
|
||||
csn(HIGH);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::print_status(uint8_t status)
|
||||
{
|
||||
printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n"),
|
||||
status,
|
||||
(status & _BV(RX_DR))?1:0,
|
||||
(status & _BV(TX_DS))?1:0,
|
||||
(status & _BV(MAX_RT))?1:0,
|
||||
((status >> RX_P_NO) & B111),
|
||||
(status & _BV(TX_FULL))?1:0
|
||||
);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::print_observe_tx(uint8_t value)
|
||||
{
|
||||
printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"),
|
||||
value,
|
||||
(value >> PLOS_CNT) & B1111,
|
||||
(value >> ARC_CNT) & B1111
|
||||
);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::print_byte_register(const char* name, uint8_t reg, uint8_t qty)
|
||||
{
|
||||
char extra_tab = strlen_P(name) < 8 ? '\t' : 0;
|
||||
printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);
|
||||
while (qty--)
|
||||
printf_P(PSTR(" 0x%02x"),read_register(reg++));
|
||||
printf_P(PSTR("\r\n"));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty)
|
||||
{
|
||||
char extra_tab = strlen_P(name) < 8 ? '\t' : 0;
|
||||
printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);
|
||||
|
||||
while (qty--)
|
||||
{
|
||||
uint8_t buffer[5];
|
||||
read_register(reg++,buffer,sizeof buffer);
|
||||
|
||||
printf_P(PSTR(" 0x"));
|
||||
uint8_t* bufptr = buffer + sizeof buffer;
|
||||
while( --bufptr >= buffer )
|
||||
printf_P(PSTR("%02x"),*bufptr);
|
||||
}
|
||||
|
||||
printf_P(PSTR("\r\n"));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
RF24::RF24(uint8_t _cepin, uint8_t _cspin):
|
||||
ce_pin(_cepin), csn_pin(_cspin), wide_band(true), p_variant(false),
|
||||
payload_size(32), ack_payload_available(false), dynamic_payloads_enabled(false),
|
||||
pipe0_reading_address(0)
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::setChannel(uint8_t channel)
|
||||
{
|
||||
// TODO: This method could take advantage of the 'wide_band' calculation
|
||||
// done in setChannel() to require certain channel spacing.
|
||||
|
||||
const uint8_t max_channel = 127;
|
||||
write_register(RF_CH,min(channel,max_channel));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::setPayloadSize(uint8_t size)
|
||||
{
|
||||
const uint8_t max_payload_size = 32;
|
||||
payload_size = min(size,max_payload_size);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::getPayloadSize(void)
|
||||
{
|
||||
return payload_size;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const char rf24_datarate_e_str_0[] PROGMEM = "1MBPS";
|
||||
static const char rf24_datarate_e_str_1[] PROGMEM = "2MBPS";
|
||||
static const char rf24_datarate_e_str_2[] PROGMEM = "250KBPS";
|
||||
static const char * const rf24_datarate_e_str_P[] PROGMEM = {
|
||||
rf24_datarate_e_str_0,
|
||||
rf24_datarate_e_str_1,
|
||||
rf24_datarate_e_str_2,
|
||||
};
|
||||
static const char rf24_model_e_str_0[] PROGMEM = "nRF24L01";
|
||||
static const char rf24_model_e_str_1[] PROGMEM = "nRF24L01+";
|
||||
static const char * const rf24_model_e_str_P[] PROGMEM = {
|
||||
rf24_model_e_str_0,
|
||||
rf24_model_e_str_1,
|
||||
};
|
||||
static const char rf24_crclength_e_str_0[] PROGMEM = "Disabled";
|
||||
static const char rf24_crclength_e_str_1[] PROGMEM = "8 bits";
|
||||
static const char rf24_crclength_e_str_2[] PROGMEM = "16 bits" ;
|
||||
static const char * const rf24_crclength_e_str_P[] PROGMEM = {
|
||||
rf24_crclength_e_str_0,
|
||||
rf24_crclength_e_str_1,
|
||||
rf24_crclength_e_str_2,
|
||||
};
|
||||
static const char rf24_pa_dbm_e_str_0[] PROGMEM = "PA_MIN";
|
||||
static const char rf24_pa_dbm_e_str_1[] PROGMEM = "PA_LOW";
|
||||
static const char rf24_pa_dbm_e_str_2[] PROGMEM = "LA_MED";
|
||||
static const char rf24_pa_dbm_e_str_3[] PROGMEM = "PA_HIGH";
|
||||
static const char * const rf24_pa_dbm_e_str_P[] PROGMEM = {
|
||||
rf24_pa_dbm_e_str_0,
|
||||
rf24_pa_dbm_e_str_1,
|
||||
rf24_pa_dbm_e_str_2,
|
||||
rf24_pa_dbm_e_str_3,
|
||||
};
|
||||
|
||||
void RF24::printDetails(void)
|
||||
{
|
||||
print_status(get_status());
|
||||
|
||||
print_address_register(PSTR("RX_ADDR_P0-1"),RX_ADDR_P0,2);
|
||||
print_byte_register(PSTR("RX_ADDR_P2-5"),RX_ADDR_P2,4);
|
||||
print_address_register(PSTR("TX_ADDR"),TX_ADDR);
|
||||
|
||||
print_byte_register(PSTR("RX_PW_P0-6"),RX_PW_P0,6);
|
||||
print_byte_register(PSTR("EN_AA"),EN_AA);
|
||||
print_byte_register(PSTR("EN_RXADDR"),EN_RXADDR);
|
||||
print_byte_register(PSTR("RF_CH"),RF_CH);
|
||||
print_byte_register(PSTR("RF_SETUP"),RF_SETUP);
|
||||
print_byte_register(PSTR("CONFIG"),CONFIG);
|
||||
print_byte_register(PSTR("DYNPD/FEATURE"),DYNPD,2);
|
||||
|
||||
printf_P(PSTR("Data Rate\t = %S\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));
|
||||
printf_P(PSTR("Model\t\t = %S\r\n"),pgm_read_word(&rf24_model_e_str_P[isPVariant()]));
|
||||
printf_P(PSTR("CRC Length\t = %S\r\n"),pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()]));
|
||||
printf_P(PSTR("PA Power\t = %S\r\n"),pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()]));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::begin(void)
|
||||
{
|
||||
// Initialize pins
|
||||
pinMode(ce_pin,OUTPUT);
|
||||
pinMode(csn_pin,OUTPUT);
|
||||
|
||||
// Initialize SPI bus
|
||||
SPI.begin();
|
||||
|
||||
ce(LOW);
|
||||
csn(HIGH);
|
||||
|
||||
// Must allow the radio time to settle else configuration bits will not necessarily stick.
|
||||
// This is actually only required following power up but some settling time also appears to
|
||||
// be required after resets too. For full coverage, we'll always assume the worst.
|
||||
// Enabling 16b CRC is by far the most obvious case if the wrong timing is used - or skipped.
|
||||
// Technically we require 4.5ms + 14us as a worst case. We'll just call it 5ms for good measure.
|
||||
// WARNING: Delay is based on P-variant whereby non-P *may* require different timing.
|
||||
delay( 5 ) ;
|
||||
|
||||
// Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier
|
||||
// WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet
|
||||
// sizes must never be used. See documentation for a more complete explanation.
|
||||
write_register(SETUP_RETR,(B0100 << ARD) | (B1111 << ARC));
|
||||
|
||||
// Restore our default PA level
|
||||
setPALevel( RF24_PA_MAX ) ;
|
||||
|
||||
// Determine if this is a p or non-p RF24 module and then
|
||||
// reset our data rate back to default value. This works
|
||||
// because a non-P variant won't allow the data rate to
|
||||
// be set to 250Kbps.
|
||||
if( setDataRate( RF24_250KBPS ) )
|
||||
{
|
||||
p_variant = true ;
|
||||
}
|
||||
|
||||
// Then set the data rate to the slowest (and most reliable) speed supported by all
|
||||
// hardware.
|
||||
setDataRate( RF24_1MBPS ) ;
|
||||
|
||||
// Initialize CRC and request 2-byte (16bit) CRC
|
||||
setCRCLength( RF24_CRC_16 ) ;
|
||||
|
||||
// Disable dynamic payloads, to match dynamic_payloads_enabled setting
|
||||
write_register(DYNPD,0);
|
||||
|
||||
// Reset current status
|
||||
// Notice reset and flush is the last thing we do
|
||||
write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||
|
||||
// Set up default configuration. Callers can always change it later.
|
||||
// This channel should be universally safe and not bleed over into adjacent
|
||||
// spectrum.
|
||||
setChannel(76);
|
||||
|
||||
// Flush buffers
|
||||
flush_rx();
|
||||
flush_tx();
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::startListening(void)
|
||||
{
|
||||
write_register(CONFIG, read_register(CONFIG) | _BV(PWR_UP) | _BV(PRIM_RX));
|
||||
write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||
|
||||
// Restore the pipe0 adddress, if exists
|
||||
if (pipe0_reading_address)
|
||||
write_register(RX_ADDR_P0, reinterpret_cast<const uint8_t*>(&pipe0_reading_address), 5);
|
||||
|
||||
// Flush buffers
|
||||
flush_rx();
|
||||
flush_tx();
|
||||
|
||||
// Go!
|
||||
ce(HIGH);
|
||||
|
||||
// wait for the radio to come up (130us actually only needed)
|
||||
delayMicroseconds(130);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::stopListening(void)
|
||||
{
|
||||
ce(LOW);
|
||||
flush_tx();
|
||||
flush_rx();
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::powerDown(void)
|
||||
{
|
||||
write_register(CONFIG,read_register(CONFIG) & ~_BV(PWR_UP));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::powerUp(void)
|
||||
{
|
||||
write_register(CONFIG,read_register(CONFIG) | _BV(PWR_UP));
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
bool RF24::write( const void* buf, uint8_t len )
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
// Begin the write
|
||||
startWrite(buf,len);
|
||||
|
||||
// ------------
|
||||
// At this point we could return from a non-blocking write, and then call
|
||||
// the rest after an interrupt
|
||||
|
||||
// Instead, we are going to block here until we get TX_DS (transmission completed and ack'd)
|
||||
// or MAX_RT (maximum retries, transmission failed). Also, we'll timeout in case the radio
|
||||
// is flaky and we get neither.
|
||||
|
||||
// IN the end, the send should be blocking. It comes back in 60ms worst case, or much faster
|
||||
// if I tighted up the retry logic. (Default settings will be 1500us.
|
||||
// Monitor the send
|
||||
uint8_t observe_tx;
|
||||
uint8_t status;
|
||||
uint32_t sent_at = millis();
|
||||
const uint32_t timeout = 500; //ms to wait for timeout
|
||||
do
|
||||
{
|
||||
status = read_register(OBSERVE_TX,&observe_tx,1);
|
||||
IF_SERIAL_DEBUG(Serial.print(observe_tx,HEX));
|
||||
}
|
||||
while( ! ( status & ( _BV(TX_DS) | _BV(MAX_RT) ) ) && ( millis() - sent_at < timeout ) );
|
||||
|
||||
// The part above is what you could recreate with your own interrupt handler,
|
||||
// and then call this when you got an interrupt
|
||||
// ------------
|
||||
|
||||
// Call this when you get an interrupt
|
||||
// The status tells us three things
|
||||
// * The send was successful (TX_DS)
|
||||
// * The send failed, too many retries (MAX_RT)
|
||||
// * There is an ack packet waiting (RX_DR)
|
||||
bool tx_ok, tx_fail;
|
||||
whatHappened(tx_ok,tx_fail,ack_payload_available);
|
||||
|
||||
//printf("%u%u%u\r\n",tx_ok,tx_fail,ack_payload_available);
|
||||
|
||||
result = tx_ok;
|
||||
IF_SERIAL_DEBUG(Serial.print(result?"...OK.":"...Failed"));
|
||||
|
||||
// Handle the ack packet
|
||||
if ( ack_payload_available )
|
||||
{
|
||||
ack_payload_length = getDynamicPayloadSize();
|
||||
IF_SERIAL_DEBUG(Serial.print("[AckPacket]/"));
|
||||
IF_SERIAL_DEBUG(Serial.println(ack_payload_length,DEC));
|
||||
}
|
||||
|
||||
// Yay, we are done.
|
||||
|
||||
// Power down
|
||||
powerDown();
|
||||
|
||||
// Flush buffers (Is this a relic of past experimentation, and not needed anymore??)
|
||||
flush_tx();
|
||||
|
||||
return result;
|
||||
}
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::startWrite( const void* buf, uint8_t len )
|
||||
{
|
||||
// Transmitter power-up
|
||||
write_register(CONFIG, ( read_register(CONFIG) | _BV(PWR_UP) ) & ~_BV(PRIM_RX) );
|
||||
delayMicroseconds(150);
|
||||
|
||||
// Send the payload
|
||||
write_payload( buf, len );
|
||||
|
||||
// Allons!
|
||||
ce(HIGH);
|
||||
delayMicroseconds(15);
|
||||
ce(LOW);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
uint8_t RF24::getDynamicPayloadSize(void)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
csn(LOW);
|
||||
SPI.transfer( R_RX_PL_WID );
|
||||
result = SPI.transfer(0xff);
|
||||
csn(HIGH);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
bool RF24::available(void)
|
||||
{
|
||||
return available(NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
bool RF24::available(uint8_t* pipe_num)
|
||||
{
|
||||
uint8_t status = get_status();
|
||||
|
||||
// Too noisy, enable if you really want lots o data!!
|
||||
//IF_SERIAL_DEBUG(print_status(status));
|
||||
|
||||
bool result = ( status & _BV(RX_DR) );
|
||||
|
||||
if (result)
|
||||
{
|
||||
// If the caller wants the pipe number, include that
|
||||
if ( pipe_num )
|
||||
*pipe_num = ( status >> RX_P_NO ) & B111;
|
||||
|
||||
// Clear the status bit
|
||||
|
||||
// ??? Should this REALLY be cleared now? Or wait until we
|
||||
// actually READ the payload?
|
||||
|
||||
write_register(STATUS,_BV(RX_DR) );
|
||||
|
||||
// Handle ack payload receipt
|
||||
if ( status & _BV(TX_DS) )
|
||||
{
|
||||
write_register(STATUS,_BV(TX_DS));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
bool RF24::read( void* buf, uint8_t len )
|
||||
{
|
||||
// Fetch the payload
|
||||
read_payload( buf, len );
|
||||
|
||||
// was this the last of the data available?
|
||||
return read_register(FIFO_STATUS) & _BV(RX_EMPTY);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready)
|
||||
{
|
||||
// Read the status & reset the status in one easy call
|
||||
// Or is that such a good idea?
|
||||
uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||
|
||||
// Report to the user what happened
|
||||
tx_ok = status & _BV(TX_DS);
|
||||
tx_fail = status & _BV(MAX_RT);
|
||||
rx_ready = status & _BV(RX_DR);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::openWritingPipe(uint64_t value)
|
||||
{
|
||||
// Note that AVR 8-bit uC's store this LSB first, and the NRF24L01(+)
|
||||
// expects it LSB first too, so we're good.
|
||||
|
||||
write_register(RX_ADDR_P0, reinterpret_cast<uint8_t*>(&value), 5);
|
||||
write_register(TX_ADDR, reinterpret_cast<uint8_t*>(&value), 5);
|
||||
|
||||
const uint8_t max_payload_size = 32;
|
||||
write_register(RX_PW_P0,min(payload_size,max_payload_size));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static const uint8_t child_pipe[] PROGMEM =
|
||||
{
|
||||
RX_ADDR_P0, RX_ADDR_P1, RX_ADDR_P2, RX_ADDR_P3, RX_ADDR_P4, RX_ADDR_P5
|
||||
};
|
||||
static const uint8_t child_payload_size[] PROGMEM =
|
||||
{
|
||||
RX_PW_P0, RX_PW_P1, RX_PW_P2, RX_PW_P3, RX_PW_P4, RX_PW_P5
|
||||
};
|
||||
static const uint8_t child_pipe_enable[] PROGMEM =
|
||||
{
|
||||
ERX_P0, ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5
|
||||
};
|
||||
|
||||
void RF24::openReadingPipe(uint8_t child, uint64_t address)
|
||||
{
|
||||
// If this is pipe 0, cache the address. This is needed because
|
||||
// openWritingPipe() will overwrite the pipe 0 address, so
|
||||
// startListening() will have to restore it.
|
||||
if (child == 0)
|
||||
pipe0_reading_address = address;
|
||||
|
||||
if (child <= 6)
|
||||
{
|
||||
// For pipes 2-5, only write the LSB
|
||||
if ( child < 2 )
|
||||
write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast<const uint8_t*>(&address), 5);
|
||||
else
|
||||
write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast<const uint8_t*>(&address), 1);
|
||||
|
||||
write_register(pgm_read_byte(&child_payload_size[child]),payload_size);
|
||||
|
||||
// Note it would be more efficient to set all of the bits for all open
|
||||
// pipes at once. However, I thought it would make the calling code
|
||||
// more simple to do it this way.
|
||||
write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child])));
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::toggle_features(void)
|
||||
{
|
||||
csn(LOW);
|
||||
SPI.transfer( ACTIVATE );
|
||||
SPI.transfer( 0x73 );
|
||||
csn(HIGH);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::enableDynamicPayloads(void)
|
||||
{
|
||||
// Enable dynamic payload throughout the system
|
||||
write_register(FEATURE,read_register(FEATURE) | _BV(EN_DPL) );
|
||||
|
||||
// If it didn't work, the features are not enabled
|
||||
if ( ! read_register(FEATURE) )
|
||||
{
|
||||
// So enable them and try again
|
||||
toggle_features();
|
||||
write_register(FEATURE,read_register(FEATURE) | _BV(EN_DPL) );
|
||||
}
|
||||
|
||||
IF_SERIAL_DEBUG(printf("FEATURE=%i\r\n",read_register(FEATURE)));
|
||||
|
||||
// Enable dynamic payload on all pipes
|
||||
//
|
||||
// Not sure the use case of only having dynamic payload on certain
|
||||
// pipes, so the library does not support it.
|
||||
write_register(DYNPD,read_register(DYNPD) | _BV(DPL_P5) | _BV(DPL_P4) | _BV(DPL_P3) | _BV(DPL_P2) | _BV(DPL_P1) | _BV(DPL_P0));
|
||||
|
||||
dynamic_payloads_enabled = true;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::enableAckPayload(void)
|
||||
{
|
||||
//
|
||||
// enable ack payload and dynamic payload features
|
||||
//
|
||||
|
||||
write_register(FEATURE,read_register(FEATURE) | _BV(EN_ACK_PAY) | _BV(EN_DPL) );
|
||||
|
||||
// If it didn't work, the features are not enabled
|
||||
if ( ! read_register(FEATURE) )
|
||||
{
|
||||
// So enable them and try again
|
||||
toggle_features();
|
||||
write_register(FEATURE,read_register(FEATURE) | _BV(EN_ACK_PAY) | _BV(EN_DPL) );
|
||||
}
|
||||
|
||||
IF_SERIAL_DEBUG(printf("FEATURE=%i\r\n",read_register(FEATURE)));
|
||||
|
||||
//
|
||||
// Enable dynamic payload on pipes 0 & 1
|
||||
//
|
||||
|
||||
write_register(DYNPD,read_register(DYNPD) | _BV(DPL_P1) | _BV(DPL_P0));
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
|
||||
{
|
||||
const uint8_t* current = reinterpret_cast<const uint8_t*>(buf);
|
||||
|
||||
csn(LOW);
|
||||
SPI.transfer( W_ACK_PAYLOAD | ( pipe & B111 ) );
|
||||
const uint8_t max_payload_size = 32;
|
||||
uint8_t data_len = min(len,max_payload_size);
|
||||
while ( data_len-- )
|
||||
SPI.transfer(*current++);
|
||||
|
||||
csn(HIGH);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
bool RF24::isAckPayloadAvailable(void)
|
||||
{
|
||||
bool result = ack_payload_available;
|
||||
ack_payload_available = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
bool RF24::isPVariant(void)
|
||||
{
|
||||
return p_variant ;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::setAutoAck(bool enable)
|
||||
{
|
||||
if ( enable )
|
||||
write_register(EN_AA, B111111);
|
||||
else
|
||||
write_register(EN_AA, 0);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::setAutoAck( uint8_t pipe, bool enable )
|
||||
{
|
||||
if ( pipe <= 6 )
|
||||
{
|
||||
uint8_t en_aa = read_register( EN_AA ) ;
|
||||
if( enable )
|
||||
{
|
||||
en_aa |= _BV(pipe) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
en_aa &= ~_BV(pipe) ;
|
||||
}
|
||||
write_register( EN_AA, en_aa ) ;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
bool RF24::testCarrier(void)
|
||||
{
|
||||
return ( read_register(CD) & 1 );
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
bool RF24::testRPD(void)
|
||||
{
|
||||
return ( read_register(RPD) & 1 ) ;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::setPALevel(rf24_pa_dbm_e level)
|
||||
{
|
||||
uint8_t setup = read_register(RF_SETUP) ;
|
||||
setup &= ~(_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;
|
||||
|
||||
// switch uses RAM (evil!)
|
||||
if ( level == RF24_PA_MAX )
|
||||
{
|
||||
setup |= (_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;
|
||||
}
|
||||
else if ( level == RF24_PA_HIGH )
|
||||
{
|
||||
setup |= _BV(RF_PWR_HIGH) ;
|
||||
}
|
||||
else if ( level == RF24_PA_LOW )
|
||||
{
|
||||
setup |= _BV(RF_PWR_LOW);
|
||||
}
|
||||
else if ( level == RF24_PA_MIN )
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
else if ( level == RF24_PA_ERROR )
|
||||
{
|
||||
// On error, go to maximum PA
|
||||
setup |= (_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;
|
||||
}
|
||||
|
||||
write_register( RF_SETUP, setup ) ;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
rf24_pa_dbm_e RF24::getPALevel(void)
|
||||
{
|
||||
rf24_pa_dbm_e result = RF24_PA_ERROR ;
|
||||
uint8_t power = read_register(RF_SETUP) & (_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;
|
||||
|
||||
// switch uses RAM (evil!)
|
||||
if ( power == (_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) )
|
||||
{
|
||||
result = RF24_PA_MAX ;
|
||||
}
|
||||
else if ( power == _BV(RF_PWR_HIGH) )
|
||||
{
|
||||
result = RF24_PA_HIGH ;
|
||||
}
|
||||
else if ( power == _BV(RF_PWR_LOW) )
|
||||
{
|
||||
result = RF24_PA_LOW ;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = RF24_PA_MIN ;
|
||||
}
|
||||
|
||||
return result ;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
bool RF24::setDataRate(rf24_datarate_e speed)
|
||||
{
|
||||
bool result = false;
|
||||
uint8_t setup = read_register(RF_SETUP) ;
|
||||
|
||||
// HIGH and LOW '00' is 1Mbs - our default
|
||||
wide_band = false ;
|
||||
setup &= ~(_BV(RF_DR_LOW) | _BV(RF_DR_HIGH)) ;
|
||||
if( speed == RF24_250KBPS )
|
||||
{
|
||||
// Must set the RF_DR_LOW to 1; RF_DR_HIGH (used to be RF_DR) is already 0
|
||||
// Making it '10'.
|
||||
wide_band = false ;
|
||||
setup |= _BV( RF_DR_LOW ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set 2Mbs, RF_DR (RF_DR_HIGH) is set 1
|
||||
// Making it '01'
|
||||
if ( speed == RF24_2MBPS )
|
||||
{
|
||||
wide_band = true ;
|
||||
setup |= _BV(RF_DR_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 1Mbs
|
||||
wide_band = false ;
|
||||
}
|
||||
}
|
||||
write_register(RF_SETUP,setup);
|
||||
|
||||
// Verify our result
|
||||
if ( read_register(RF_SETUP) == setup )
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
wide_band = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
rf24_datarate_e RF24::getDataRate( void )
|
||||
{
|
||||
rf24_datarate_e result ;
|
||||
uint8_t dr = read_register(RF_SETUP) & (_BV(RF_DR_LOW) | _BV(RF_DR_HIGH));
|
||||
|
||||
// switch uses RAM (evil!)
|
||||
// Order matters in our case below
|
||||
if ( dr == _BV(RF_DR_LOW) )
|
||||
{
|
||||
// '10' = 250KBPS
|
||||
result = RF24_250KBPS ;
|
||||
}
|
||||
else if ( dr == _BV(RF_DR_HIGH) )
|
||||
{
|
||||
// '01' = 2MBPS
|
||||
result = RF24_2MBPS ;
|
||||
}
|
||||
else
|
||||
{
|
||||
// '00' = 1MBPS
|
||||
result = RF24_1MBPS ;
|
||||
}
|
||||
return result ;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::setCRCLength(rf24_crclength_e length)
|
||||
{
|
||||
uint8_t config = read_register(CONFIG) & ~( _BV(CRCO) | _BV(EN_CRC)) ;
|
||||
|
||||
// switch uses RAM (evil!)
|
||||
if ( length == RF24_CRC_DISABLED )
|
||||
{
|
||||
// Do nothing, we turned it off above.
|
||||
}
|
||||
else if ( length == RF24_CRC_8 )
|
||||
{
|
||||
config |= _BV(EN_CRC);
|
||||
}
|
||||
else
|
||||
{
|
||||
config |= _BV(EN_CRC);
|
||||
config |= _BV( CRCO );
|
||||
}
|
||||
write_register( CONFIG, config ) ;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
rf24_crclength_e RF24::getCRCLength(void)
|
||||
{
|
||||
rf24_crclength_e result = RF24_CRC_DISABLED;
|
||||
uint8_t config = read_register(CONFIG) & ( _BV(CRCO) | _BV(EN_CRC)) ;
|
||||
|
||||
if ( config & _BV(EN_CRC ) )
|
||||
{
|
||||
if ( config & _BV(CRCO) )
|
||||
result = RF24_CRC_16;
|
||||
else
|
||||
result = RF24_CRC_8;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void RF24::disableCRC( void )
|
||||
{
|
||||
uint8_t disable = read_register(CONFIG) & ~_BV(EN_CRC) ;
|
||||
write_register( CONFIG, disable ) ;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
void RF24::setRetries(uint8_t delay, uint8_t count)
|
||||
{
|
||||
write_register(SETUP_RETR,(delay&0xf)<<ARD | (count&0xf)<<ARC);
|
||||
}
|
||||
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
|
||||
816
digistump-sam/libraries/RF24/RF24.h
Normal file
816
digistump-sam/libraries/RF24/RF24.h
Normal file
@@ -0,0 +1,816 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file RF24.h
|
||||
*
|
||||
* Class declaration for RF24 and helper enums
|
||||
*/
|
||||
|
||||
#ifndef __RF24_H__
|
||||
#define __RF24_H__
|
||||
|
||||
#ifdef __arm__
|
||||
#define SPI_CLOCK_DIV4 21
|
||||
#define _BV(bit) (1 << (bit))
|
||||
#define printf_P printf
|
||||
#endif
|
||||
|
||||
#include <RF24_config.h>
|
||||
|
||||
/**
|
||||
* Power Amplifier level.
|
||||
*
|
||||
* For use with setPALevel()
|
||||
*/
|
||||
typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ;
|
||||
|
||||
/**
|
||||
* Data rate. How fast data moves through the air.
|
||||
*
|
||||
* For use with setDataRate()
|
||||
*/
|
||||
typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e;
|
||||
|
||||
/**
|
||||
* CRC Length. How big (if any) of a CRC is included.
|
||||
*
|
||||
* For use with setCRCLength()
|
||||
*/
|
||||
typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e;
|
||||
|
||||
/**
|
||||
* Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
|
||||
*/
|
||||
|
||||
class RF24
|
||||
{
|
||||
private:
|
||||
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
|
||||
uint8_t csn_pin; /**< SPI Chip select */
|
||||
bool wide_band; /* 2Mbs data rate in use? */
|
||||
bool p_variant; /* False for RF24L01 and true for RF24L01P */
|
||||
uint8_t payload_size; /**< Fixed size of payloads */
|
||||
bool ack_payload_available; /**< Whether there is an ack payload waiting */
|
||||
bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
|
||||
uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. */
|
||||
uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @name Low-level internal interface.
|
||||
*
|
||||
* Protected methods that address the chip directly. Regular users cannot
|
||||
* ever call these. They are documented for completeness and for developers who
|
||||
* may want to extend this class.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Set chip select pin
|
||||
*
|
||||
* Running SPI bus at PI_CLOCK_DIV2 so we don't waste time transferring data
|
||||
* and best of all, we make use of the radio's FIFO buffers. A lower speed
|
||||
* means we're less likely to effectively leverage our FIFOs and pay a higher
|
||||
* AVR runtime cost as toll.
|
||||
*
|
||||
* @param mode HIGH to take this unit off the SPI bus, LOW to put it on
|
||||
*/
|
||||
void csn(int mode);
|
||||
|
||||
/**
|
||||
* Set chip enable
|
||||
*
|
||||
* @param level HIGH to actively begin transmission or LOW to put in standby. Please see data sheet
|
||||
* for a much more detailed description of this pin.
|
||||
*/
|
||||
void ce(int level);
|
||||
|
||||
/**
|
||||
* Read a chunk of data in from a register
|
||||
*
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param buf Where to put the data
|
||||
* @param len How many bytes of data to transfer
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Read single byte from a register
|
||||
*
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @return Current value of register @p reg
|
||||
*/
|
||||
uint8_t read_register(uint8_t reg);
|
||||
|
||||
/**
|
||||
* Write a chunk of data to a register
|
||||
*
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param buf Where to get the data
|
||||
* @param len How many bytes of data to transfer
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Write a single byte to a register
|
||||
*
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param value The new value to write
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t write_register(uint8_t reg, uint8_t value);
|
||||
|
||||
/**
|
||||
* Write the transmit payload
|
||||
*
|
||||
* The size of data written is the fixed payload size, see getPayloadSize()
|
||||
*
|
||||
* @param buf Where to get the data
|
||||
* @param len Number of bytes to be sent
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t write_payload(const void* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Read the receive payload
|
||||
*
|
||||
* The size of data read is the fixed payload size, see getPayloadSize()
|
||||
*
|
||||
* @param buf Where to put the data
|
||||
* @param len Maximum number of bytes to read
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t read_payload(void* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Empty the receive buffer
|
||||
*
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t flush_rx(void);
|
||||
|
||||
/**
|
||||
* Empty the transmit buffer
|
||||
*
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t flush_tx(void);
|
||||
|
||||
/**
|
||||
* Retrieve the current status of the chip
|
||||
*
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t get_status(void);
|
||||
|
||||
/**
|
||||
* Decode and print the given status to stdout
|
||||
*
|
||||
* @param status Status value to print
|
||||
*
|
||||
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
|
||||
*/
|
||||
void print_status(uint8_t status);
|
||||
|
||||
/**
|
||||
* Decode and print the given 'observe_tx' value to stdout
|
||||
*
|
||||
* @param value The observe_tx value to print
|
||||
*
|
||||
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
|
||||
*/
|
||||
void print_observe_tx(uint8_t value);
|
||||
|
||||
/**
|
||||
* Print the name and value of an 8-bit register to stdout
|
||||
*
|
||||
* Optionally it can print some quantity of successive
|
||||
* registers on the same line. This is useful for printing a group
|
||||
* of related registers on one line.
|
||||
*
|
||||
* @param name Name of the register
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param qty How many successive registers to print
|
||||
*/
|
||||
void print_byte_register(const char* name, uint8_t reg, uint8_t qty = 1);
|
||||
|
||||
/**
|
||||
* Print the name and value of a 40-bit address register to stdout
|
||||
*
|
||||
* Optionally it can print some quantity of successive
|
||||
* registers on the same line. This is useful for printing a group
|
||||
* of related registers on one line.
|
||||
*
|
||||
* @param name Name of the register
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param qty How many successive registers to print
|
||||
*/
|
||||
void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1);
|
||||
|
||||
/**
|
||||
* Turn on or off the special features of the chip
|
||||
*
|
||||
* The chip has certain 'features' which are only available when the 'features'
|
||||
* are enabled. See the datasheet for details.
|
||||
*/
|
||||
void toggle_features(void);
|
||||
/**@}*/
|
||||
|
||||
public:
|
||||
/**
|
||||
* @name Primary public interface
|
||||
*
|
||||
* These are the main methods you need to operate the chip
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Creates a new instance of this driver. Before using, you create an instance
|
||||
* and send in the unique pins that this chip is connected to.
|
||||
*
|
||||
* @param _cepin The pin attached to Chip Enable on the RF module
|
||||
* @param _cspin The pin attached to Chip Select
|
||||
*/
|
||||
RF24(uint8_t _cepin, uint8_t _cspin);
|
||||
|
||||
/**
|
||||
* Begin operation of the chip
|
||||
*
|
||||
* Call this in setup(), before calling any other methods.
|
||||
*/
|
||||
void begin(void);
|
||||
|
||||
/**
|
||||
* Start listening on the pipes opened for reading.
|
||||
*
|
||||
* Be sure to call openReadingPipe() first. Do not call write() while
|
||||
* in this mode, without first calling stopListening(). Call
|
||||
* isAvailable() to check for incoming traffic, and read() to get it.
|
||||
*/
|
||||
void startListening(void);
|
||||
|
||||
/**
|
||||
* Stop listening for incoming messages
|
||||
*
|
||||
* Do this before calling write().
|
||||
*/
|
||||
void stopListening(void);
|
||||
|
||||
/**
|
||||
* Write to the open writing pipe
|
||||
*
|
||||
* Be sure to call openWritingPipe() first to set the destination
|
||||
* of where to write to.
|
||||
*
|
||||
* This blocks until the message is successfully acknowledged by
|
||||
* the receiver or the timeout/retransmit maxima are reached. In
|
||||
* the current configuration, the max delay here is 60ms.
|
||||
*
|
||||
* The maximum size of data written is the fixed payload size, see
|
||||
* getPayloadSize(). However, you can write less, and the remainder
|
||||
* will just be filled with zeroes.
|
||||
*
|
||||
* @param buf Pointer to the data to be sent
|
||||
* @param len Number of bytes to be sent
|
||||
* @return True if the payload was delivered successfully false if not
|
||||
*/
|
||||
bool write( const void* buf, uint8_t len );
|
||||
|
||||
/**
|
||||
* Test whether there are bytes available to be read
|
||||
*
|
||||
* @return True if there is a payload available, false if none is
|
||||
*/
|
||||
bool available(void);
|
||||
|
||||
/**
|
||||
* Read the payload
|
||||
*
|
||||
* Return the last payload received
|
||||
*
|
||||
* The size of data read is the fixed payload size, see getPayloadSize()
|
||||
*
|
||||
* @note I specifically chose 'void*' as a data type to make it easier
|
||||
* for beginners to use. No casting needed.
|
||||
*
|
||||
* @param buf Pointer to a buffer where the data should be written
|
||||
* @param len Maximum number of bytes to read into the buffer
|
||||
* @return True if the payload was delivered successfully false if not
|
||||
*/
|
||||
bool read( void* buf, uint8_t len );
|
||||
|
||||
/**
|
||||
* Open a pipe for writing
|
||||
*
|
||||
* Only one pipe can be open at once, but you can change the pipe
|
||||
* you'll listen to. Do not call this while actively listening.
|
||||
* Remember to stopListening() first.
|
||||
*
|
||||
* Addresses are 40-bit hex values, e.g.:
|
||||
*
|
||||
* @code
|
||||
* openWritingPipe(0xF0F0F0F0F0);
|
||||
* @endcode
|
||||
*
|
||||
* @param address The 40-bit address of the pipe to open. This can be
|
||||
* any value whatsoever, as long as you are the only one writing to it
|
||||
* and only one other radio is listening to it. Coordinate these pipe
|
||||
* addresses amongst nodes on the network.
|
||||
*/
|
||||
void openWritingPipe(uint64_t address);
|
||||
|
||||
/**
|
||||
* Open a pipe for reading
|
||||
*
|
||||
* Up to 6 pipes can be open for reading at once. Open all the
|
||||
* reading pipes, and then call startListening().
|
||||
*
|
||||
* @see openWritingPipe
|
||||
*
|
||||
* @warning Pipes 1-5 should share the first 32 bits.
|
||||
* Only the least significant byte should be unique, e.g.
|
||||
* @code
|
||||
* openReadingPipe(1,0xF0F0F0F0AA);
|
||||
* openReadingPipe(2,0xF0F0F0F066);
|
||||
* @endcode
|
||||
*
|
||||
* @warning Pipe 0 is also used by the writing pipe. So if you open
|
||||
* pipe 0 for reading, and then startListening(), it will overwrite the
|
||||
* writing pipe. Ergo, do an openWritingPipe() again before write().
|
||||
*
|
||||
* @todo Enforce the restriction that pipes 1-5 must share the top 32 bits
|
||||
*
|
||||
* @param number Which pipe# to open, 0-5.
|
||||
* @param address The 40-bit address of the pipe to open.
|
||||
*/
|
||||
void openReadingPipe(uint8_t number, uint64_t address);
|
||||
|
||||
/**@}*/
|
||||
/**
|
||||
* @name Optional Configurators
|
||||
*
|
||||
* Methods you can use to get or set the configuration of the chip.
|
||||
* None are required. Calling begin() sets up a reasonable set of
|
||||
* defaults.
|
||||
*/
|
||||
/**@{*/
|
||||
/**
|
||||
* Set the number and delay of retries upon failed submit
|
||||
*
|
||||
* @param delay How long to wait between each retry, in multiples of 250us,
|
||||
* max is 15. 0 means 250us, 15 means 4000us.
|
||||
* @param count How many retries before giving up, max 15
|
||||
*/
|
||||
void setRetries(uint8_t delay, uint8_t count);
|
||||
|
||||
/**
|
||||
* Set RF communication channel
|
||||
*
|
||||
* @param channel Which RF channel to communicate on, 0-127
|
||||
*/
|
||||
void setChannel(uint8_t channel);
|
||||
|
||||
/**
|
||||
* Set Static Payload Size
|
||||
*
|
||||
* This implementation uses a pre-stablished fixed payload size for all
|
||||
* transmissions. If this method is never called, the driver will always
|
||||
* transmit the maximum payload size (32 bytes), no matter how much
|
||||
* was sent to write().
|
||||
*
|
||||
* @todo Implement variable-sized payloads feature
|
||||
*
|
||||
* @param size The number of bytes in the payload
|
||||
*/
|
||||
void setPayloadSize(uint8_t size);
|
||||
|
||||
/**
|
||||
* Get Static Payload Size
|
||||
*
|
||||
* @see setPayloadSize()
|
||||
*
|
||||
* @return The number of bytes in the payload
|
||||
*/
|
||||
uint8_t getPayloadSize(void);
|
||||
|
||||
/**
|
||||
* Get Dynamic Payload Size
|
||||
*
|
||||
* For dynamic payloads, this pulls the size of the payload off
|
||||
* the chip
|
||||
*
|
||||
* @return Payload length of last-received dynamic payload
|
||||
*/
|
||||
uint8_t getDynamicPayloadSize(void);
|
||||
|
||||
/**
|
||||
* Enable custom payloads on the acknowledge packets
|
||||
*
|
||||
* Ack payloads are a handy way to return data back to senders without
|
||||
* manually changing the radio modes on both units.
|
||||
*
|
||||
* @see examples/pingpair_pl/pingpair_pl.pde
|
||||
*/
|
||||
void enableAckPayload(void);
|
||||
|
||||
/**
|
||||
* Enable dynamically-sized payloads
|
||||
*
|
||||
* This way you don't always have to send large packets just to send them
|
||||
* once in a while. This enables dynamic payloads on ALL pipes.
|
||||
*
|
||||
* @see examples/pingpair_pl/pingpair_dyn.pde
|
||||
*/
|
||||
void enableDynamicPayloads(void);
|
||||
|
||||
/**
|
||||
* Determine whether the hardware is an nRF24L01+ or not.
|
||||
*
|
||||
* @return true if the hardware is nRF24L01+ (or compatible) and false
|
||||
* if its not.
|
||||
*/
|
||||
bool isPVariant(void) ;
|
||||
|
||||
/**
|
||||
* Enable or disable auto-acknowlede packets
|
||||
*
|
||||
* This is enabled by default, so it's only needed if you want to turn
|
||||
* it off for some reason.
|
||||
*
|
||||
* @param enable Whether to enable (true) or disable (false) auto-acks
|
||||
*/
|
||||
void setAutoAck(bool enable);
|
||||
|
||||
/**
|
||||
* Enable or disable auto-acknowlede packets on a per pipeline basis.
|
||||
*
|
||||
* AA is enabled by default, so it's only needed if you want to turn
|
||||
* it off/on for some reason on a per pipeline basis.
|
||||
*
|
||||
* @param pipe Which pipeline to modify
|
||||
* @param enable Whether to enable (true) or disable (false) auto-acks
|
||||
*/
|
||||
void setAutoAck( uint8_t pipe, bool enable ) ;
|
||||
|
||||
/**
|
||||
* Set Power Amplifier (PA) level to one of four levels.
|
||||
* Relative mnemonics have been used to allow for future PA level
|
||||
* changes. According to 6.5 of the nRF24L01+ specification sheet,
|
||||
* they translate to: RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm,
|
||||
* RF24_PA_MED=-6dBM, and RF24_PA_HIGH=0dBm.
|
||||
*
|
||||
* @param level Desired PA level.
|
||||
*/
|
||||
void setPALevel( rf24_pa_dbm_e level ) ;
|
||||
|
||||
/**
|
||||
* Fetches the current PA level.
|
||||
*
|
||||
* @return Returns a value from the rf24_pa_dbm_e enum describing
|
||||
* the current PA setting. Please remember, all values represented
|
||||
* by the enum mnemonics are negative dBm. See setPALevel for
|
||||
* return value descriptions.
|
||||
*/
|
||||
rf24_pa_dbm_e getPALevel( void ) ;
|
||||
|
||||
/**
|
||||
* Set the transmission data rate
|
||||
*
|
||||
* @warning setting RF24_250KBPS will fail for non-plus units
|
||||
*
|
||||
* @param speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
|
||||
* @return true if the change was successful
|
||||
*/
|
||||
bool setDataRate(rf24_datarate_e speed);
|
||||
|
||||
/**
|
||||
* Fetches the transmission data rate
|
||||
*
|
||||
* @return Returns the hardware's currently configured datarate. The value
|
||||
* is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the
|
||||
* rf24_datarate_e enum.
|
||||
*/
|
||||
rf24_datarate_e getDataRate( void ) ;
|
||||
|
||||
/**
|
||||
* Set the CRC length
|
||||
*
|
||||
* @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
|
||||
*/
|
||||
void setCRCLength(rf24_crclength_e length);
|
||||
|
||||
/**
|
||||
* Get the CRC length
|
||||
*
|
||||
* @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
|
||||
*/
|
||||
rf24_crclength_e getCRCLength(void);
|
||||
|
||||
/**
|
||||
* Disable CRC validation
|
||||
*
|
||||
*/
|
||||
void disableCRC( void ) ;
|
||||
|
||||
/**@}*/
|
||||
/**
|
||||
* @name Advanced Operation
|
||||
*
|
||||
* Methods you can use to drive the chip in more advanced ways
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Print a giant block of debugging information to stdout
|
||||
*
|
||||
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
|
||||
*/
|
||||
void printDetails(void);
|
||||
|
||||
/**
|
||||
* Enter low-power mode
|
||||
*
|
||||
* To return to normal power mode, either write() some data or
|
||||
* startListening, or powerUp().
|
||||
*/
|
||||
void powerDown(void);
|
||||
|
||||
/**
|
||||
* Leave low-power mode - making radio more responsive
|
||||
*
|
||||
* To return to low power mode, call powerDown().
|
||||
*/
|
||||
void powerUp(void) ;
|
||||
|
||||
/**
|
||||
* Test whether there are bytes available to be read
|
||||
*
|
||||
* Use this version to discover on which pipe the message
|
||||
* arrived.
|
||||
*
|
||||
* @param[out] pipe_num Which pipe has the payload available
|
||||
* @return True if there is a payload available, false if none is
|
||||
*/
|
||||
bool available(uint8_t* pipe_num);
|
||||
|
||||
/**
|
||||
* Non-blocking write to the open writing pipe
|
||||
*
|
||||
* Just like write(), but it returns immediately. To find out what happened
|
||||
* to the send, catch the IRQ and then call whatHappened().
|
||||
*
|
||||
* @see write()
|
||||
* @see whatHappened()
|
||||
*
|
||||
* @param buf Pointer to the data to be sent
|
||||
* @param len Number of bytes to be sent
|
||||
* @return True if the payload was delivered successfully false if not
|
||||
*/
|
||||
void startWrite( const void* buf, uint8_t len );
|
||||
|
||||
/**
|
||||
* Write an ack payload for the specified pipe
|
||||
*
|
||||
* The next time a message is received on @p pipe, the data in @p buf will
|
||||
* be sent back in the acknowledgement.
|
||||
*
|
||||
* @warning According to the data sheet, only three of these can be pending
|
||||
* at any time. I have not tested this.
|
||||
*
|
||||
* @param pipe Which pipe# (typically 1-5) will get this response.
|
||||
* @param buf Pointer to data that is sent
|
||||
* @param len Length of the data to send, up to 32 bytes max. Not affected
|
||||
* by the static payload set by setPayloadSize().
|
||||
*/
|
||||
void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Determine if an ack payload was received in the most recent call to
|
||||
* write().
|
||||
*
|
||||
* Call read() to retrieve the ack payload.
|
||||
*
|
||||
* @warning Calling this function clears the internal flag which indicates
|
||||
* a payload is available. If it returns true, you must read the packet
|
||||
* out as the very next interaction with the radio, or the results are
|
||||
* undefined.
|
||||
*
|
||||
* @return True if an ack payload is available.
|
||||
*/
|
||||
bool isAckPayloadAvailable(void);
|
||||
|
||||
/**
|
||||
* Call this when you get an interrupt to find out why
|
||||
*
|
||||
* Tells you what caused the interrupt, and clears the state of
|
||||
* interrupts.
|
||||
*
|
||||
* @param[out] tx_ok The send was successful (TX_DS)
|
||||
* @param[out] tx_fail The send failed, too many retries (MAX_RT)
|
||||
* @param[out] rx_ready There is a message waiting to be read (RX_DS)
|
||||
*/
|
||||
void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready);
|
||||
|
||||
/**
|
||||
* Test whether there was a carrier on the line for the
|
||||
* previous listening period.
|
||||
*
|
||||
* Useful to check for interference on the current channel.
|
||||
*
|
||||
* @return true if was carrier, false if not
|
||||
*/
|
||||
bool testCarrier(void);
|
||||
|
||||
/**
|
||||
* Test whether a signal (carrier or otherwise) greater than
|
||||
* or equal to -64dBm is present on the channel. Valid only
|
||||
* on nRF24L01P (+) hardware. On nRF24L01, use testCarrier().
|
||||
*
|
||||
* Useful to check for interference on the current channel and
|
||||
* channel hopping strategies.
|
||||
*
|
||||
* @return true if signal => -64dBm, false if not
|
||||
*/
|
||||
bool testRPD(void) ;
|
||||
|
||||
/**@}*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @example GettingStarted.pde
|
||||
*
|
||||
* This is an example which corresponds to my "Getting Started" blog post:
|
||||
* <a style="text-align:center" href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>.
|
||||
*
|
||||
* It is an example of how to use the RF24 class. Write this sketch to two
|
||||
* different nodes. Put one of the nodes into 'transmit' mode by connecting
|
||||
* with the serial monitor and sending a 'T'. The ping node sends the current
|
||||
* time to the pong node, which responds by sending the value back. The ping
|
||||
* node can then see how long the whole cycle took.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example nordic_fob.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class to receive signals from the
|
||||
* Sparkfun Nordic FOB. See http://www.sparkfun.com/products/8602 .
|
||||
* Thanks to Kirk Mower for providing test hardware.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example led_remote.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class to control a remote
|
||||
* bank of LED's using buttons on a remote control.
|
||||
*
|
||||
* Every time the buttons change on the remote, the entire state of
|
||||
* buttons is send to the led board, which displays the state.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class. Write this sketch to two
|
||||
* different nodes, connect the role_pin to ground on one. The ping node sends
|
||||
* the current time to the pong node, which responds by sending the value back.
|
||||
* The ping node can then see how long the whole cycle took.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair_maple.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class on the Maple. For a more
|
||||
* detailed explanation, see my blog post:
|
||||
* <a href="http://maniacbug.wordpress.com/2011/12/14/nrf24l01-running-on-maple-3/">nRF24L01+ Running on Maple</a>
|
||||
*
|
||||
* It will communicate well to an Arduino-based unit as well, so it's not for only Maple-to-Maple communication.
|
||||
*
|
||||
* Write this sketch to two different nodes,
|
||||
* connect the role_pin to ground on one. The ping node sends the current time to the pong node,
|
||||
* which responds by sending the value back. The ping node can then see how long the whole cycle
|
||||
* took.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example starping.pde
|
||||
*
|
||||
* This sketch is a more complex example of using the RF24 library for Arduino.
|
||||
* Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the
|
||||
* role_pin low, and the others will be 'ping transmit' units. The ping units
|
||||
* unit will send out the value of millis() once a second. The pong unit will
|
||||
* respond back with a copy of the value. Each ping unit can get that response
|
||||
* back, and determine how long the whole cycle took.
|
||||
*
|
||||
* This example requires a bit more complexity to determine which unit is which.
|
||||
* The pong receiver is identified by having its role_pin tied to ground.
|
||||
* The ping senders are further differentiated by a byte in eeprom.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair_pl.pde
|
||||
*
|
||||
* This is an example of how to do two-way communication without changing
|
||||
* transmit/receive modes. Here, a payload is set to the transmitter within
|
||||
* the Ack packet of each transmission. Note that the payload is set BEFORE
|
||||
* the sender's message arrives.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair_irq.pde
|
||||
*
|
||||
* This is an example of how to user interrupts to interact with the radio.
|
||||
* It builds on the pingpair_pl example, and uses ack payloads.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair_sleepy.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class to create a battery-
|
||||
* efficient system. It is just like the pingpair.pde example, but the
|
||||
* ping node powers down the radio and sleeps the MCU after every
|
||||
* ping/pong cycle.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example scanner.pde
|
||||
*
|
||||
* Example to detect interference on the various channels available.
|
||||
* This is a good diagnostic tool to check whether you're picking a
|
||||
* good channel for your application.
|
||||
*
|
||||
* Inspired by cpixip.
|
||||
* See http://arduino.cc/forum/index.php/topic,54795.0.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* @mainpage Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
|
||||
*
|
||||
* @section Goals Design Goals
|
||||
*
|
||||
* This library is designed to be...
|
||||
* @li Maximally compliant with the intended operation of the chip
|
||||
* @li Easy for beginners to use
|
||||
* @li Consumed with a public interface that's similiar to other Arduino standard libraries
|
||||
*
|
||||
* @section News News
|
||||
*
|
||||
* NOW COMPATIBLE WITH ARDUINO 1.0 - The 'master' branch and all examples work with both Arduino 1.0 and earlier versions.
|
||||
* Please <a href="https://github.com/maniacbug/RF24/issues/new">open an issue</a> if you find any problems using it with any version of Arduino.
|
||||
*
|
||||
* NOW COMPATIBLE WITH MAPLE - RF24 has been tested with the
|
||||
* <a href="http://leaflabs.com/store/#Maple-Native">Maple Native</a>,
|
||||
* and should work with any Maple board. See the pingpair_maple example.
|
||||
* Note that only the pingpair_maple example has been tested on Maple, although
|
||||
* the others can certainly be adapted.
|
||||
*
|
||||
* @section Useful Useful References
|
||||
*
|
||||
* Please refer to:
|
||||
*
|
||||
* @li <a href="http://maniacbug.github.com/RF24/">Documentation Main Page</a>
|
||||
* @li <a href="http://maniacbug.github.com/RF24/classRF24.html">RF24 Class Documentation</a>
|
||||
* @li <a href="https://github.com/maniacbug/RF24/">Source Code</a>
|
||||
* @li <a href="https://github.com/maniacbug/RF24/archives/master">Downloads Page</a>
|
||||
* @li <a href="http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf">Chip Datasheet</a>
|
||||
*
|
||||
* This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
|
||||
* the SPI hardware will go into 'slave' mode.
|
||||
*
|
||||
* @section More More Information
|
||||
*
|
||||
* @subpage FAQ
|
||||
*
|
||||
* @section Projects Projects
|
||||
*
|
||||
* Stuff I have built with RF24
|
||||
*
|
||||
* <img src="http://farm7.staticflickr.com/6044/6307669179_a8d19298a6_m.jpg" width="240" height="160" alt="RF24 Getting Started - Finished Product">
|
||||
*
|
||||
* <a style="text-align:center" href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>
|
||||
*
|
||||
* <img src="http://farm8.staticflickr.com/7159/6645514331_38eb2bdeaa_m.jpg" width="240" height="160" alt="Nordic FOB and nRF24L01+">
|
||||
*
|
||||
* <a style="text-align:center" href="http://maniacbug.wordpress.com/2012/01/08/nordic-fob/">Using the Sparkfun Nordic FOB</a>
|
||||
*
|
||||
* <img src="http://farm7.staticflickr.com/6097/6224308836_b9b3b421a3_m.jpg" width="240" height="160" alt="RF Duinode V3 (2V4)">
|
||||
*
|
||||
* <a href="http://maniacbug.wordpress.com/2011/10/19/sensor-node/">Low-Power Wireless Sensor Node</a>
|
||||
*
|
||||
* <img src="http://farm8.staticflickr.com/7012/6489477865_b56edb629b_m.jpg" width="240" height="161" alt="nRF24L01+ connected to Leaf Labs Maple Native">
|
||||
*
|
||||
* <a href="http://maniacbug.wordpress.com/2011/12/14/nrf24l01-running-on-maple-3/">nRF24L01+ Running on Maple</a>
|
||||
*/
|
||||
|
||||
#endif // __RF24_H__
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
|
||||
65
digistump-sam/libraries/RF24/RF24_config.h
Normal file
65
digistump-sam/libraries/RF24/RF24_config.h
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef __RF24_CONFIG_H__
|
||||
#define __RF24_CONFIG_H__
|
||||
|
||||
#if ARDUINO < 100
|
||||
#include <WProgram.h>
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
// Stuff that is normally provided by Arduino
|
||||
#ifdef ARDUINO
|
||||
#include <SPI.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
extern HardwareSPI SPI;
|
||||
#define _BV(x) (1<<(x))
|
||||
#endif
|
||||
|
||||
#undef SERIAL_DEBUG
|
||||
#ifdef SERIAL_DEBUG
|
||||
#define IF_SERIAL_DEBUG(x) ({x;})
|
||||
#else
|
||||
#define IF_SERIAL_DEBUG(x)
|
||||
#endif
|
||||
|
||||
// Avoid spurious warnings
|
||||
#if 1
|
||||
#if ! defined( NATIVE ) && defined( ARDUINO )
|
||||
#undef PROGMEM
|
||||
#define PROGMEM __attribute__(( section(".progmem.data") ))
|
||||
#undef PSTR
|
||||
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Progmem is Arduino-specific
|
||||
#ifdef ARDUINO
|
||||
#include <avr/pgmspace.h>
|
||||
#define PRIPSTR "%S"
|
||||
#else
|
||||
typedef char const char;
|
||||
typedef uint16_t prog_uint16_t;
|
||||
#define PSTR(x) (x)
|
||||
#define printf_P printf
|
||||
#define strlen_P strlen
|
||||
#define PROGMEM
|
||||
#define pgm_read_word(p) (*(p))
|
||||
#define PRIPSTR "%s"
|
||||
#endif
|
||||
|
||||
#endif // __RF24_CONFIG_H__
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
835
digistump-sam/libraries/RF24/doxygen-custom.css
Normal file
835
digistump-sam/libraries/RF24/doxygen-custom.css
Normal file
@@ -0,0 +1,835 @@
|
||||
/* The standard CSS for doxygen */
|
||||
|
||||
body, table, div, p, dl {
|
||||
font-family: Lucida Grande, Verdana, Geneva, Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* @group Heading Levels */
|
||||
|
||||
h1 {
|
||||
font-size: 150%;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 150%;
|
||||
font-weight: bold;
|
||||
margin: 10px 2px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 120%;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
dt {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.multicol {
|
||||
-moz-column-gap: 1em;
|
||||
-webkit-column-gap: 1em;
|
||||
-moz-column-count: 3;
|
||||
-webkit-column-count: 3;
|
||||
}
|
||||
|
||||
p.startli, p.startdd, p.starttd {
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
p.endli {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
p.enddd {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
p.endtd {
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
caption {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
span.legend {
|
||||
font-size: 70%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h3.version {
|
||||
font-size: 90%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.qindex, div.navtab{
|
||||
background-color: #EBEFF6;
|
||||
border: 1px solid #A3B4D7;
|
||||
text-align: center;
|
||||
margin: 2px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
div.qindex, div.navpath {
|
||||
width: 100%;
|
||||
line-height: 140%;
|
||||
}
|
||||
|
||||
div.navtab {
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
/* @group Link Styling */
|
||||
|
||||
a {
|
||||
color: #3D578C;
|
||||
font-weight: normal;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.contents a:visited {
|
||||
color: #4665A2;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a.qindex {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a.qindexHL {
|
||||
font-weight: bold;
|
||||
background-color: #9CAFD4;
|
||||
color: #ffffff;
|
||||
border: 1px double #869DCA;
|
||||
}
|
||||
|
||||
.contents a.qindexHL:visited {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
a.el {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a.elRef {
|
||||
}
|
||||
|
||||
a.code {
|
||||
color: #4665A2;
|
||||
}
|
||||
|
||||
a.codeRef {
|
||||
color: #4665A2;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
dl.el {
|
||||
margin-left: -1cm;
|
||||
}
|
||||
|
||||
.fragment {
|
||||
font-family: monospace, fixed;
|
||||
font-size: 105%;
|
||||
}
|
||||
|
||||
pre.fragment {
|
||||
border: 1px solid #C4CFE5;
|
||||
background-color: #FBFCFD;
|
||||
padding: 4px 6px;
|
||||
margin: 4px 8px 4px 2px;
|
||||
overflow: auto;
|
||||
word-wrap: break-word;
|
||||
font-size: 9pt;
|
||||
line-height: 125%;
|
||||
}
|
||||
|
||||
div.ah {
|
||||
background-color: black;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
margin-bottom: 3px;
|
||||
margin-top: 3px;
|
||||
padding: 0.2em;
|
||||
border: solid thin #333;
|
||||
border-radius: 0.5em;
|
||||
-webkit-border-radius: .5em;
|
||||
-moz-border-radius: .5em;
|
||||
box-shadow: 2px 2px 3px #999;
|
||||
-webkit-box-shadow: 2px 2px 3px #999;
|
||||
-moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px;
|
||||
background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#000),color-stop(0.3, #444));
|
||||
background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000);
|
||||
}
|
||||
|
||||
div.groupHeader {
|
||||
margin-left: 16px;
|
||||
margin-top: 12px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.groupText {
|
||||
margin-left: 16px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
body {
|
||||
background: white;
|
||||
color: black;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.contents {
|
||||
margin-top: 10px;
|
||||
margin-left: 10px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
td.indexkey {
|
||||
background-color: #EBEFF6;
|
||||
font-weight: bold;
|
||||
border: 1px solid #C4CFE5;
|
||||
margin: 2px 0px 2px 0;
|
||||
padding: 2px 10px;
|
||||
}
|
||||
|
||||
td.indexvalue {
|
||||
background-color: #EBEFF6;
|
||||
border: 1px solid #C4CFE5;
|
||||
padding: 2px 10px;
|
||||
margin: 2px 0px;
|
||||
}
|
||||
|
||||
tr.memlist {
|
||||
background-color: #EEF1F7;
|
||||
}
|
||||
|
||||
p.formulaDsp {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
img.formulaDsp {
|
||||
|
||||
}
|
||||
|
||||
img.formulaInl {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.center {
|
||||
text-align: center;
|
||||
margin-top: 0px;
|
||||
margin-bottom: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
div.center img {
|
||||
border: 0px;
|
||||
}
|
||||
|
||||
address.footer {
|
||||
text-align: right;
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
img.footer {
|
||||
border: 0px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* @group Code Colorization */
|
||||
|
||||
span.keyword {
|
||||
color: #008000
|
||||
}
|
||||
|
||||
span.keywordtype {
|
||||
color: #604020
|
||||
}
|
||||
|
||||
span.keywordflow {
|
||||
color: #e08000
|
||||
}
|
||||
|
||||
span.comment {
|
||||
color: #800000
|
||||
}
|
||||
|
||||
span.preprocessor {
|
||||
color: #806020
|
||||
}
|
||||
|
||||
span.stringliteral {
|
||||
color: #002080
|
||||
}
|
||||
|
||||
span.charliteral {
|
||||
color: #008080
|
||||
}
|
||||
|
||||
span.vhdldigit {
|
||||
color: #ff00ff
|
||||
}
|
||||
|
||||
span.vhdlchar {
|
||||
color: #000000
|
||||
}
|
||||
|
||||
span.vhdlkeyword {
|
||||
color: #700070
|
||||
}
|
||||
|
||||
span.vhdllogic {
|
||||
color: #ff0000
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/*
|
||||
.search {
|
||||
color: #003399;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
form.search {
|
||||
margin-bottom: 0px;
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
input.search {
|
||||
font-size: 75%;
|
||||
color: #000080;
|
||||
font-weight: normal;
|
||||
background-color: #e8eef2;
|
||||
}
|
||||
*/
|
||||
|
||||
td.tiny {
|
||||
font-size: 75%;
|
||||
}
|
||||
|
||||
.dirtab {
|
||||
padding: 4px;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #A3B4D7;
|
||||
}
|
||||
|
||||
th.dirtab {
|
||||
background: #EBEFF6;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
hr {
|
||||
height: 0px;
|
||||
border: none;
|
||||
border-top: 1px solid #4A6AAA;
|
||||
}
|
||||
|
||||
hr.footer {
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
/* @group Member Descriptions */
|
||||
|
||||
table.memberdecls {
|
||||
border-spacing: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.mdescLeft, .mdescRight,
|
||||
.memItemLeft, .memItemRight,
|
||||
.memTemplItemLeft, .memTemplItemRight, .memTemplParams {
|
||||
background-color: #F9FAFC;
|
||||
border: none;
|
||||
margin: 4px;
|
||||
padding: 1px 0 0 8px;
|
||||
}
|
||||
|
||||
.mdescLeft, .mdescRight {
|
||||
padding: 0px 8px 4px 8px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.memItemLeft, .memItemRight, .memTemplParams {
|
||||
border-top: 1px solid #C4CFE5;
|
||||
}
|
||||
|
||||
.memItemLeft, .memTemplItemLeft {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.memItemRight {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.memTemplParams {
|
||||
color: #4665A2;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Member Details */
|
||||
|
||||
/* Styles for detailed member documentation */
|
||||
|
||||
.memtemplate {
|
||||
font-size: 80%;
|
||||
color: #4665A2;
|
||||
font-weight: normal;
|
||||
margin-left: 9px;
|
||||
}
|
||||
|
||||
.memnav {
|
||||
background-color: #EBEFF6;
|
||||
border: 1px solid #A3B4D7;
|
||||
text-align: center;
|
||||
margin: 2px;
|
||||
margin-right: 15px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.mempage {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.memitem {
|
||||
padding: 0;
|
||||
margin-bottom: 10px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.memname {
|
||||
white-space: nowrap;
|
||||
font-weight: bold;
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
.memproto {
|
||||
border-top: 1px solid #A8B8D9;
|
||||
border-left: 1px solid #A8B8D9;
|
||||
border-right: 1px solid #A8B8D9;
|
||||
padding: 6px 0px 6px 0px;
|
||||
color: #253555;
|
||||
font-weight: bold;
|
||||
text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9);
|
||||
/* opera specific markup */
|
||||
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
|
||||
border-top-right-radius: 8px;
|
||||
border-top-left-radius: 8px;
|
||||
/* firefox specific markup */
|
||||
-moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px;
|
||||
-moz-border-radius-topright: 8px;
|
||||
-moz-border-radius-topleft: 8px;
|
||||
/* webkit specific markup */
|
||||
-webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
|
||||
-webkit-border-top-right-radius: 8px;
|
||||
-webkit-border-top-left-radius: 8px;
|
||||
background-image:url('nav_f.png');
|
||||
background-repeat:repeat-x;
|
||||
background-color: #E2E8F2;
|
||||
|
||||
}
|
||||
|
||||
.memdoc {
|
||||
border-bottom: 1px solid #A8B8D9;
|
||||
border-left: 1px solid #A8B8D9;
|
||||
border-right: 1px solid #A8B8D9;
|
||||
padding: 2px 5px;
|
||||
background-color: #FBFCFD;
|
||||
border-top-width: 0;
|
||||
/* opera specific markup */
|
||||
border-bottom-left-radius: 8px;
|
||||
border-bottom-right-radius: 8px;
|
||||
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
|
||||
/* firefox specific markup */
|
||||
-moz-border-radius-bottomleft: 8px;
|
||||
-moz-border-radius-bottomright: 8px;
|
||||
-moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px;
|
||||
background-image: -moz-linear-gradient(center top, #FFFFFF 0%, #FFFFFF 60%, #F7F8FB 95%, #EEF1F7);
|
||||
/* webkit specific markup */
|
||||
-webkit-border-bottom-left-radius: 8px;
|
||||
-webkit-border-bottom-right-radius: 8px;
|
||||
-webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15);
|
||||
background-image: -webkit-gradient(linear,center top,center bottom,from(#FFFFFF), color-stop(0.6,#FFFFFF), color-stop(0.60,#FFFFFF), color-stop(0.95,#F7F8FB), to(#EEF1F7));
|
||||
}
|
||||
|
||||
.paramkey {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.paramtype {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.paramname {
|
||||
color: #602020;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.paramname em {
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.params, .retval, .exception, .tparams {
|
||||
border-spacing: 6px 2px;
|
||||
}
|
||||
|
||||
.params .paramname, .retval .paramname {
|
||||
font-weight: bold;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.params .paramtype {
|
||||
font-style: italic;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.params .paramdir {
|
||||
font-family: "courier new",courier,monospace;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Directory (tree) */
|
||||
|
||||
/* for the tree view */
|
||||
|
||||
.ftvtree {
|
||||
font-family: sans-serif;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
/* these are for tree view when used as main index */
|
||||
|
||||
.directory {
|
||||
font-size: 9pt;
|
||||
font-weight: bold;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.directory h3 {
|
||||
margin: 0px;
|
||||
margin-top: 1em;
|
||||
font-size: 11pt;
|
||||
}
|
||||
|
||||
/*
|
||||
The following two styles can be used to replace the root node title
|
||||
with an image of your choice. Simply uncomment the next two styles,
|
||||
specify the name of your image and be sure to set 'height' to the
|
||||
proper pixel height of your image.
|
||||
*/
|
||||
|
||||
/*
|
||||
.directory h3.swap {
|
||||
height: 61px;
|
||||
background-repeat: no-repeat;
|
||||
background-image: url("yourimage.gif");
|
||||
}
|
||||
.directory h3.swap span {
|
||||
display: none;
|
||||
}
|
||||
*/
|
||||
|
||||
.directory > h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.directory p {
|
||||
margin: 0px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.directory div {
|
||||
display: none;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.directory img {
|
||||
vertical-align: -30%;
|
||||
}
|
||||
|
||||
/* these are for tree view when not used as main index */
|
||||
|
||||
.directory-alt {
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.directory-alt h3 {
|
||||
margin: 0px;
|
||||
margin-top: 1em;
|
||||
font-size: 11pt;
|
||||
}
|
||||
|
||||
.directory-alt > h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.directory-alt p {
|
||||
margin: 0px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.directory-alt div {
|
||||
display: none;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.directory-alt img {
|
||||
vertical-align: -30%;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
div.dynheader {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
address {
|
||||
font-style: normal;
|
||||
color: #2A3D61;
|
||||
}
|
||||
|
||||
table.doxtable {
|
||||
border-collapse:collapse;
|
||||
}
|
||||
|
||||
table.doxtable td, table.doxtable th {
|
||||
border: 1px solid #2D4068;
|
||||
padding: 3px 7px 2px;
|
||||
}
|
||||
|
||||
table.doxtable th {
|
||||
background-color: #374F7F;
|
||||
color: #FFFFFF;
|
||||
font-size: 110%;
|
||||
padding-bottom: 4px;
|
||||
padding-top: 5px;
|
||||
text-align:left;
|
||||
}
|
||||
|
||||
.tabsearch {
|
||||
top: 0px;
|
||||
left: 10px;
|
||||
height: 36px;
|
||||
background-image: url('tab_b.png');
|
||||
z-index: 101;
|
||||
overflow: hidden;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.navpath ul
|
||||
{
|
||||
font-size: 11px;
|
||||
background-image:url('tab_b.png');
|
||||
background-repeat:repeat-x;
|
||||
height:30px;
|
||||
line-height:30px;
|
||||
color:#8AA0CC;
|
||||
border:solid 1px #C2CDE4;
|
||||
overflow:hidden;
|
||||
margin:0px;
|
||||
padding:0px;
|
||||
}
|
||||
|
||||
.navpath li
|
||||
{
|
||||
list-style-type:none;
|
||||
float:left;
|
||||
padding-left:10px;
|
||||
padding-right:15px;
|
||||
background-image:url('bc_s.png');
|
||||
background-repeat:no-repeat;
|
||||
background-position:right;
|
||||
color:#364D7C;
|
||||
}
|
||||
|
||||
.navpath li.navelem a
|
||||
{
|
||||
height:32px;
|
||||
display:block;
|
||||
text-decoration: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.navpath li.navelem a:hover
|
||||
{
|
||||
color:#6884BD;
|
||||
}
|
||||
|
||||
.navpath li.footer
|
||||
{
|
||||
list-style-type:none;
|
||||
float:right;
|
||||
padding-left:10px;
|
||||
padding-right:15px;
|
||||
background-image:none;
|
||||
background-repeat:no-repeat;
|
||||
background-position:right;
|
||||
color:#364D7C;
|
||||
font-size: 8pt;
|
||||
}
|
||||
|
||||
|
||||
div.summary
|
||||
{
|
||||
float: right;
|
||||
font-size: 8pt;
|
||||
padding-right: 5px;
|
||||
width: 50%;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
div.summary a
|
||||
{
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
div.ingroups
|
||||
{
|
||||
font-size: 8pt;
|
||||
padding-left: 5px;
|
||||
width: 50%;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
div.ingroups a
|
||||
{
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
div.header
|
||||
{
|
||||
background-image:url('nav_h.png');
|
||||
background-repeat:repeat-x;
|
||||
background-color: #F9FAFC;
|
||||
margin: 0px;
|
||||
border-bottom: 1px solid #C4CFE5;
|
||||
}
|
||||
|
||||
div.headertitle
|
||||
{
|
||||
padding: 5px 5px 5px 10px;
|
||||
}
|
||||
|
||||
dl
|
||||
{
|
||||
padding: 0 0 0 10px;
|
||||
}
|
||||
|
||||
dl.note, dl.warning, dl.attention, dl.pre, dl.post, dl.invariant, dl.deprecated, dl.todo, dl.test, dl.bug
|
||||
{
|
||||
border-left:4px solid;
|
||||
padding: 0 0 0 6px;
|
||||
}
|
||||
|
||||
dl.note
|
||||
{
|
||||
border-color: #D0C000;
|
||||
}
|
||||
|
||||
dl.warning, dl.attention
|
||||
{
|
||||
border-color: #FF0000;
|
||||
}
|
||||
|
||||
dl.pre, dl.post, dl.invariant
|
||||
{
|
||||
border-color: #00D000;
|
||||
}
|
||||
|
||||
dl.deprecated
|
||||
{
|
||||
border-color: #505050;
|
||||
}
|
||||
|
||||
dl.todo
|
||||
{
|
||||
border-color: #00C0E0;
|
||||
}
|
||||
|
||||
dl.test
|
||||
{
|
||||
border-color: #3030E0;
|
||||
}
|
||||
|
||||
dl.bug
|
||||
{
|
||||
border-color: #C08050;
|
||||
}
|
||||
|
||||
#projectlogo
|
||||
{
|
||||
text-align: center;
|
||||
vertical-align: bottom;
|
||||
border-collapse: separate;
|
||||
}
|
||||
|
||||
#projectlogo img
|
||||
{
|
||||
border: 0px none;
|
||||
}
|
||||
|
||||
#projectname
|
||||
{
|
||||
font: 300% Tahoma, Arial,sans-serif;
|
||||
margin: 0px;
|
||||
padding: 2px 0px;
|
||||
}
|
||||
|
||||
#projectbrief
|
||||
{
|
||||
font: 120% Tahoma, Arial,sans-serif;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#projectnumber
|
||||
{
|
||||
font: 50% Tahoma, Arial,sans-serif;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#titlearea
|
||||
{
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
width: 100%;
|
||||
border-bottom: 1px solid #5373B4;
|
||||
}
|
||||
|
||||
.image
|
||||
{
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.dotgraph
|
||||
{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mscgraph
|
||||
{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.caption
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example for Getting Started with nRF24L01+ radios.
|
||||
*
|
||||
* This is an example of how to use the RF24 class. Write this sketch to two
|
||||
* different nodes. Put one of the nodes into 'transmit' mode by connecting
|
||||
* with the serial monitor and sending a 'T'. The ping node sends the current
|
||||
* time to the pong node, which responds by sending the value back. The ping
|
||||
* node can then see how long the whole cycle took.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Radio pipe addresses for the 2 nodes to communicate.
|
||||
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes
|
||||
// in this system. Doing so greatly simplifies testing.
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_ping_out = 1, role_pong_back } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role = role_pong_back;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/GettingStarted/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
printf("*** PRESS 'T' to begin transmitting to the other node\n\r");
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
// optionally, increase the delay between retries & # of retries
|
||||
radio.setRetries(15,15);
|
||||
|
||||
// optionally, reduce the payload size. seems to
|
||||
// improve reliability
|
||||
//radio.setPayloadSize(8);
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// This simple sketch opens two pipes for these two nodes to communicate
|
||||
// back and forth.
|
||||
// Open 'our' pipe for writing
|
||||
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
|
||||
|
||||
//if ( role == role_ping_out )
|
||||
{
|
||||
//radio.openWritingPipe(pipes[0]);
|
||||
radio.openReadingPipe(1,pipes[1]);
|
||||
}
|
||||
//else
|
||||
{
|
||||
//radio.openWritingPipe(pipes[1]);
|
||||
//radio.openReadingPipe(1,pipes[0]);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Ping out role. Repeatedly send the current time
|
||||
//
|
||||
|
||||
if (role == role_ping_out)
|
||||
{
|
||||
// First, stop listening so we can talk.
|
||||
radio.stopListening();
|
||||
|
||||
// Take the time, and send it. This will block until complete
|
||||
unsigned long time = millis();
|
||||
printf("Now sending %lu...",time);
|
||||
bool ok = radio.write( &time, sizeof(unsigned long) );
|
||||
|
||||
if (ok)
|
||||
printf("ok...");
|
||||
else
|
||||
printf("failed.\n\r");
|
||||
|
||||
// Now, continue listening
|
||||
radio.startListening();
|
||||
|
||||
// Wait here until we get a response, or timeout (250ms)
|
||||
unsigned long started_waiting_at = millis();
|
||||
bool timeout = false;
|
||||
while ( ! radio.available() && ! timeout )
|
||||
if (millis() - started_waiting_at > 200 )
|
||||
timeout = true;
|
||||
|
||||
// Describe the results
|
||||
if ( timeout )
|
||||
{
|
||||
printf("Failed, response timed out.\n\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grab the response, compare, and send to debugging spew
|
||||
unsigned long got_time;
|
||||
radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
|
||||
}
|
||||
|
||||
// Try again 1s later
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
//
|
||||
// Pong back role. Receive each packet, dump it out, and send it back
|
||||
//
|
||||
|
||||
if ( role == role_pong_back )
|
||||
{
|
||||
// if there is data ready
|
||||
if ( radio.available() )
|
||||
{
|
||||
// Dump the payloads until we've gotten everything
|
||||
unsigned long got_time;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Fetch the payload, and see if this was the last one.
|
||||
done = radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got payload %lu...",got_time);
|
||||
|
||||
// Delay just a little bit to let the other unit
|
||||
// make the transition to receiver
|
||||
delay(20);
|
||||
}
|
||||
|
||||
// First, stop listening so we can talk
|
||||
radio.stopListening();
|
||||
|
||||
// Send the final one back.
|
||||
radio.write( &got_time, sizeof(unsigned long) );
|
||||
printf("Sent response.\n\r");
|
||||
|
||||
// Now, resume listening so we catch the next packets.
|
||||
radio.startListening();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Change roles
|
||||
//
|
||||
|
||||
if ( Serial.available() )
|
||||
{
|
||||
char c = toupper(Serial.read());
|
||||
if ( c == 'T' && role == role_pong_back )
|
||||
{
|
||||
printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r");
|
||||
|
||||
// Become the primary transmitter (ping out)
|
||||
role = role_ping_out;
|
||||
radio.openWritingPipe(pipes[0]);
|
||||
radio.openReadingPipe(1,pipes[1]);
|
||||
}
|
||||
else if ( c == 'R' && role == role_ping_out )
|
||||
{
|
||||
printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r");
|
||||
|
||||
// Become the primary receiver (pong back)
|
||||
role = role_pong_back;
|
||||
radio.openWritingPipe(pipes[1]);
|
||||
radio.openReadingPipe(1,pipes[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
||||
210
digistump-sam/libraries/RF24/examples/GettingStarted/Jamfile
Normal file
210
digistump-sam/libraries/RF24/examples/GettingStarted/Jamfile
Normal file
@@ -0,0 +1,210 @@
|
||||
# (1) Project Information
|
||||
|
||||
PROJECT_LIBS = SPI RF24 ;
|
||||
|
||||
# (2) Board Information
|
||||
|
||||
UPLOAD_PROTOCOL ?= arduino ;
|
||||
UPLOAD_SPEED ?= 57600 ;
|
||||
MCU ?= atmega328p ;
|
||||
F_CPU ?= 16000000 ;
|
||||
CORE ?= arduino ;
|
||||
VARIANT ?= standard ;
|
||||
ARDUINO_VERSION ?= 100 ;
|
||||
|
||||
# (3) USB Ports
|
||||
|
||||
PORTS = p4 p6 p9 u0 u1 u2 ;
|
||||
PORT_p6 = /dev/tty.usbserial-A600eHIs ;
|
||||
PORT_p4 = /dev/tty.usbserial-A40081RP ;
|
||||
PORT_p9 = /dev/tty.usbserial-A9007LmI ;
|
||||
PORT_u0 = /dev/ttyUSB0 ;
|
||||
PORT_u1 = /dev/ttyUSB1 ;
|
||||
PORT_u2 = /dev/ttyUSB2 ;
|
||||
|
||||
# (4) Location of AVR tools
|
||||
#
|
||||
# This configuration assumes using avr-tools that were obtained separate from the Arduino
|
||||
# distribution.
|
||||
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
AVR_BIN = /usr/local/avrtools/bin ;
|
||||
AVR_ETC = /usr/local/avrtools/etc ;
|
||||
AVR_INCLUDE = /usr/local/avrtools/include ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR_BIN ?= /usr/bin ;
|
||||
AVR_INCLUDE ?= /usr/lib/avr/include ;
|
||||
AVR_ETC = /etc ;
|
||||
}
|
||||
|
||||
# (5) Directories where Arduino core and libraries are located
|
||||
|
||||
ARDUINO_DIR ?= /opt/Arduino ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
|
||||
#
|
||||
# --------------------------------------------------
|
||||
# Below this line usually never needs to be modified
|
||||
#
|
||||
|
||||
# Tool locations
|
||||
|
||||
CC = $(AVR_BIN)/avr-gcc ;
|
||||
C++ = $(AVR_BIN)/avr-g++ ;
|
||||
LINK = $(AVR_BIN)/avr-gcc ;
|
||||
OBJCOPY = $(AVR_BIN)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_BIN)/avrdude ;
|
||||
|
||||
# Flags
|
||||
|
||||
DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
OPTIM = -Os ;
|
||||
CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ;
|
||||
C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ;
|
||||
LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ;
|
||||
AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ;
|
||||
|
||||
# Search everywhere for headers
|
||||
|
||||
HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ;
|
||||
|
||||
# Output locations
|
||||
|
||||
LOCATE_TARGET = $(F_CPU) ;
|
||||
LOCATE_SOURCE = $(F_CPU) ;
|
||||
|
||||
#
|
||||
# Custom rules
|
||||
#
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_SOURCE) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
if ( $(ARDUINO_VERSION) < 100 )
|
||||
{
|
||||
ARDUINO_H = WProgram.h ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ARDUINO_H = Arduino.h ;
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <$(ARDUINO_H)>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule C++Pde
|
||||
{
|
||||
local _CPP = $(>:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
C++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule UserObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .ino : C++Pde $(<) : $(>) ;
|
||||
case .pde : C++Pde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Objects
|
||||
{
|
||||
local _i ;
|
||||
|
||||
for _i in [ FGristFiles $(<) ]
|
||||
{
|
||||
local _b = $(_i:B)$(SUFOBJ) ;
|
||||
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
|
||||
Object $(_o) : $(_i) ;
|
||||
Depends obj : $(_o) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Main
|
||||
{
|
||||
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Hex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions Hex
|
||||
{
|
||||
$(OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule Upload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
UploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions UploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
#
|
||||
# Targets
|
||||
#
|
||||
|
||||
# Grab everything from the core directory
|
||||
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ;
|
||||
|
||||
# Grab everything from the current dir
|
||||
PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ;
|
||||
|
||||
# Main output executable
|
||||
MAIN = $(PWD:B).elf ;
|
||||
|
||||
Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
|
||||
Hex $(MAIN:B).hex : $(MAIN) ;
|
||||
|
||||
# Upload targets
|
||||
for _p in $(PORTS)
|
||||
{
|
||||
Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
206
digistump-sam/libraries/RF24/examples/led_remote/Jamfile
Normal file
206
digistump-sam/libraries/RF24/examples/led_remote/Jamfile
Normal file
@@ -0,0 +1,206 @@
|
||||
PROJECT_NAME = $(PWD:B) ;
|
||||
PROJECT_DIR = . ;
|
||||
PROJECT_LIBS = SPI RF24 ;
|
||||
|
||||
OUT_DIR = ojam ;
|
||||
F_CPU = 16000000 ;
|
||||
MCU = atmega328p ;
|
||||
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
|
||||
|
||||
UPLOAD_RATE = 57600 ;
|
||||
AVRDUDE_PROTOCOL = stk500v1 ;
|
||||
COM = 33 ;
|
||||
|
||||
# Host-specific overrides for locations
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
ARDUINO_VERSION = 22 ;
|
||||
OLD_DIR = /opt/arduino-0021 ;
|
||||
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
|
||||
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
|
||||
ARDUINO_DIR = /opt/Arduino ;
|
||||
ARDUINO_AVR = /usr/lib/avr/include ;
|
||||
}
|
||||
|
||||
# Where is everything?
|
||||
ARDUINO_VERSION ?= 22 ;
|
||||
AVR_TOOLS_PATH ?= /usr/bin ;
|
||||
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
|
||||
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
|
||||
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
|
||||
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
|
||||
|
||||
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
CTUNING = -ffunction-sections -fdata-sections ;
|
||||
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
|
||||
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
|
||||
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
|
||||
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
|
||||
|
||||
# Search everywhere for headers
|
||||
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
|
||||
|
||||
# Grab everything from the core directory
|
||||
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
|
||||
|
||||
# In addition to explicitly-specified program modules, pick up anything from the current
|
||||
# dir.
|
||||
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
|
||||
|
||||
# Shortcut for the out files
|
||||
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
|
||||
|
||||
# AvrDude setup
|
||||
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule AvrCc
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrCc
|
||||
{
|
||||
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule AvrC++
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrC++
|
||||
{
|
||||
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <WProgram.h>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule AvrPde
|
||||
{
|
||||
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
AvrC++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule AvrObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .c : AvrCc $(<) : $(>) ;
|
||||
case .cpp : AvrC++ $(<) : $(>) ;
|
||||
case .pde : AvrPde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrObjects
|
||||
{
|
||||
for _I in $(<)
|
||||
{
|
||||
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrMainFromObjects
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
MkDir $(<:D) ;
|
||||
Depends all : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrMainFromObjects
|
||||
{
|
||||
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
|
||||
}
|
||||
|
||||
rule AvrMain
|
||||
{
|
||||
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
|
||||
AvrObjects $(>) ;
|
||||
}
|
||||
|
||||
rule AvrHex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrHex
|
||||
{
|
||||
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule AvrUpload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
AvrUploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions AvrUploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
|
||||
AvrHex $(OUT).hex : $(OUT).elf ;
|
||||
|
||||
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
|
||||
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
|
||||
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;
|
||||
|
||||
255
digistump-sam/libraries/RF24/examples/led_remote/led_remote.pde
Normal file
255
digistump-sam/libraries/RF24/examples/led_remote/led_remote.pde
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example LED Remote
|
||||
*
|
||||
* This is an example of how to use the RF24 class to control a remote
|
||||
* bank of LED's using buttons on a remote control.
|
||||
*
|
||||
* On the 'remote', connect any number of buttons or switches from
|
||||
* an arduino pin to ground. Update 'button_pins' to reflect the
|
||||
* pins used.
|
||||
*
|
||||
* On the 'led' board, connect the same number of LED's from an
|
||||
* arduino pin to a resistor to ground. Update 'led_pins' to reflect
|
||||
* the pins used. Also connect a separate pin to ground and change
|
||||
* the 'role_pin'. This tells the sketch it's running on the LED board.
|
||||
*
|
||||
* Every time the buttons change on the remote, the entire state of
|
||||
* buttons is send to the led board, which displays the state.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'led' board receiver
|
||||
// Leave open to be the 'remote' transmitter
|
||||
const int role_pin = A4;
|
||||
|
||||
// Pins on the remote for buttons
|
||||
const uint8_t button_pins[] = { 2,3,4,5,6,7 };
|
||||
const uint8_t num_button_pins = sizeof(button_pins);
|
||||
|
||||
// Pins on the LED board for LED's
|
||||
const uint8_t led_pins[] = { 2,3,4,5,6,7 };
|
||||
const uint8_t num_led_pins = sizeof(led_pins);
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Single radio pipe address for the 2 nodes to communicate.
|
||||
const uint64_t pipe = 0xE8E8F0F0E1LL;
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes in this
|
||||
// system. Doing so greatly simplifies testing. The hardware itself specifies
|
||||
// which node it is.
|
||||
//
|
||||
// This is done through the role_pin
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_remote = 1, role_led } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Remote", "LED Board"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role;
|
||||
|
||||
//
|
||||
// Payload
|
||||
//
|
||||
|
||||
uint8_t button_states[num_button_pins];
|
||||
uint8_t led_states[num_led_pins];
|
||||
|
||||
//
|
||||
// Setup
|
||||
//
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Role
|
||||
//
|
||||
|
||||
// set up the role pin
|
||||
pinMode(role_pin, INPUT);
|
||||
digitalWrite(role_pin,HIGH);
|
||||
delay(20); // Just to get a solid reading on the role pin
|
||||
|
||||
// read the address pin, establish our role
|
||||
if ( digitalRead(role_pin) )
|
||||
role = role_remote;
|
||||
else
|
||||
role = role_led;
|
||||
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/led_remote/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// This simple sketch opens a single pipes for these two nodes to communicate
|
||||
// back and forth. One listens on it, the other talks to it.
|
||||
|
||||
if ( role == role_remote )
|
||||
{
|
||||
radio.openWritingPipe(pipe);
|
||||
}
|
||||
else
|
||||
{
|
||||
radio.openReadingPipe(1,pipe);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
if ( role == role_led )
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
|
||||
//
|
||||
// Set up buttons / LED's
|
||||
//
|
||||
|
||||
// Set pull-up resistors for all buttons
|
||||
if ( role == role_remote )
|
||||
{
|
||||
int i = num_button_pins;
|
||||
while(i--)
|
||||
{
|
||||
pinMode(button_pins[i],INPUT);
|
||||
digitalWrite(button_pins[i],HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
// Turn LED's ON until we start getting keys
|
||||
if ( role == role_led )
|
||||
{
|
||||
int i = num_led_pins;
|
||||
while(i--)
|
||||
{
|
||||
pinMode(led_pins[i],OUTPUT);
|
||||
led_states[i] = HIGH;
|
||||
digitalWrite(led_pins[i],led_states[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Loop
|
||||
//
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Remote role. If the state of any button has changed, send the whole state of
|
||||
// all buttons.
|
||||
//
|
||||
|
||||
if ( role == role_remote )
|
||||
{
|
||||
// Get the current state of buttons, and
|
||||
// Test if the current state is different from the last state we sent
|
||||
int i = num_button_pins;
|
||||
bool different = false;
|
||||
while(i--)
|
||||
{
|
||||
uint8_t state = ! digitalRead(button_pins[i]);
|
||||
if ( state != button_states[i] )
|
||||
{
|
||||
different = true;
|
||||
button_states[i] = state;
|
||||
}
|
||||
}
|
||||
|
||||
// Send the state of the buttons to the LED board
|
||||
if ( different )
|
||||
{
|
||||
printf("Now sending...");
|
||||
bool ok = radio.write( button_states, num_button_pins );
|
||||
if (ok)
|
||||
printf("ok\n\r");
|
||||
else
|
||||
printf("failed\n\r");
|
||||
}
|
||||
|
||||
// Try again in a short while
|
||||
delay(20);
|
||||
}
|
||||
|
||||
//
|
||||
// LED role. Receive the state of all buttons, and reflect that in the LEDs
|
||||
//
|
||||
|
||||
if ( role == role_led )
|
||||
{
|
||||
// if there is data ready
|
||||
if ( radio.available() )
|
||||
{
|
||||
// Dump the payloads until we've gotten everything
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Fetch the payload, and see if this was the last one.
|
||||
done = radio.read( button_states, num_button_pins );
|
||||
|
||||
// Spew it
|
||||
printf("Got buttons\n\r");
|
||||
|
||||
// For each button, if the button now on, then toggle the LED
|
||||
int i = num_led_pins;
|
||||
while(i--)
|
||||
{
|
||||
if ( button_states[i] )
|
||||
{
|
||||
led_states[i] ^= HIGH;
|
||||
digitalWrite(led_pins[i],led_states[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
39
digistump-sam/libraries/RF24/examples/led_remote/printf.h
Normal file
39
digistump-sam/libraries/RF24/examples/led_remote/printf.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
219
digistump-sam/libraries/RF24/examples/nordic_fob/Jamfile
Normal file
219
digistump-sam/libraries/RF24/examples/nordic_fob/Jamfile
Normal file
@@ -0,0 +1,219 @@
|
||||
# (1) Project Information
|
||||
|
||||
PROJECT_LIBS = RF24 SPI ;
|
||||
PROJECT_DIRS = $(PWD) ;
|
||||
|
||||
# (2) Board Information
|
||||
|
||||
UPLOAD_PROTOCOL ?= stk500v1 ;
|
||||
UPLOAD_SPEED ?= 115200 ;
|
||||
MCU ?= atmega328p ;
|
||||
F_CPU ?= 16000000 ;
|
||||
CORE ?= arduino ;
|
||||
VARIANT ?= standard ;
|
||||
ARDUINO_VERSION ?= 100 ;
|
||||
|
||||
# (3) USB Ports
|
||||
|
||||
PORTS = p4 p6 p9 u0 u1 u2 ;
|
||||
PORT_p6 = /dev/tty.usbserial-A600eHIs ;
|
||||
PORT_p4 = /dev/tty.usbserial-A40081RP ;
|
||||
PORT_p9 = /dev/tty.usbserial-A9007LmI ;
|
||||
PORT_u0 = /dev/ttyUSB0 ;
|
||||
PORT_u1 = /dev/ttyUSB1 ;
|
||||
PORT_u2 = /dev/ttyUSB2 ;
|
||||
|
||||
# (4) Location of AVR tools
|
||||
#
|
||||
# This configuration assumes using avr-tools that were obtained separate from the Arduino
|
||||
# distribution.
|
||||
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
AVR_BIN = /usr/local/avrtools/bin ;
|
||||
AVR_ETC = /usr/local/avrtools/etc ;
|
||||
AVR_INCLUDE = /usr/local/avrtools/include ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR_BIN = /usr/bin ;
|
||||
AVR_INCLUDE = /usr/lib/avr/include ;
|
||||
AVR_ETC = /etc ;
|
||||
}
|
||||
|
||||
# (5) Directories where Arduino core and libraries are located
|
||||
|
||||
ARDUINO_DIR ?= /opt/Arduino ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
|
||||
#
|
||||
# --------------------------------------------------
|
||||
# Below this line usually never needs to be modified
|
||||
#
|
||||
|
||||
# Tool locations
|
||||
|
||||
CC = $(AVR_BIN)/avr-gcc ;
|
||||
C++ = $(AVR_BIN)/avr-g++ ;
|
||||
LINK = $(AVR_BIN)/avr-gcc ;
|
||||
AR = $(AVR_BIN)/avr-ar rcs ;
|
||||
RANLIB = ;
|
||||
OBJCOPY = $(AVR_BIN)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_BIN)/avrdude ;
|
||||
|
||||
# Flags
|
||||
|
||||
DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
OPTIM = -Os ;
|
||||
CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ;
|
||||
C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ;
|
||||
LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ;
|
||||
AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ;
|
||||
|
||||
# Search everywhere for headers
|
||||
|
||||
HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ;
|
||||
|
||||
# Output locations
|
||||
|
||||
LOCATE_TARGET = $(F_CPU) ;
|
||||
LOCATE_SOURCE = $(F_CPU) ;
|
||||
|
||||
#
|
||||
# Custom rules
|
||||
#
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_SOURCE) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
if ( $(ARDUINO_VERSION) < 100 )
|
||||
{
|
||||
ARDUINO_H = WProgram.h ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ARDUINO_H = Arduino.h ;
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <$(ARDUINO_H)>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule C++Pde
|
||||
{
|
||||
local _CPP = $(>:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
C++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule UserObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .ino : C++Pde $(<) : $(>) ;
|
||||
case .pde : C++Pde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Objects
|
||||
{
|
||||
local _i ;
|
||||
|
||||
for _i in [ FGristFiles $(<) ]
|
||||
{
|
||||
local _b = $(_i:B)$(SUFOBJ) ;
|
||||
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
|
||||
Object $(_o) : $(_i) ;
|
||||
Depends obj : $(_o) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Library
|
||||
{
|
||||
LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Main
|
||||
{
|
||||
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Hex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions Hex
|
||||
{
|
||||
$(OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule Upload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
UploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions UploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
rule Arduino
|
||||
{
|
||||
LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ;
|
||||
Main $(<) : $(>) ;
|
||||
LinkLibraries $(<) : libs core ;
|
||||
Hex $(<:B).hex : $(<) ;
|
||||
for _p in $(PORTS)
|
||||
{
|
||||
Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Targets
|
||||
#
|
||||
|
||||
# Grab everything from the core directory
|
||||
Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ;
|
||||
|
||||
# Main output executable
|
||||
Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ;
|
||||
142
digistump-sam/libraries/RF24/examples/nordic_fob/nordic_fob.pde
Normal file
142
digistump-sam/libraries/RF24/examples/nordic_fob/nordic_fob.pde
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
Copyright (C) 2012 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example Nordic FOB Receiver
|
||||
*
|
||||
* This is an example of how to use the RF24 class to receive signals from the
|
||||
* Sparkfun Nordic FOB. Thanks to Kirk Mower for providing test hardware.
|
||||
*
|
||||
* See blog post at http://maniacbug.wordpress.com/2012/01/08/nordic-fob/
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <RF24.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
//
|
||||
// Payload
|
||||
//
|
||||
|
||||
struct payload_t
|
||||
{
|
||||
uint8_t buttons;
|
||||
uint16_t id;
|
||||
uint8_t empty;
|
||||
};
|
||||
|
||||
const char* button_names[] = { "Up", "Down", "Left", "Right", "Center" };
|
||||
const int num_buttons = 5;
|
||||
|
||||
//
|
||||
// Forward declarations
|
||||
//
|
||||
|
||||
uint16_t flip_endian(uint16_t in);
|
||||
|
||||
//
|
||||
// Setup
|
||||
//
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\r\nRF24/examples/nordic_fob/\r\n");
|
||||
|
||||
//
|
||||
// Setup and configure rf radio according to the built-in parameters
|
||||
// of the FOB.
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
radio.setChannel(2);
|
||||
radio.setPayloadSize(4);
|
||||
radio.setAutoAck(false);
|
||||
radio.setCRCLength(RF24_CRC_8);
|
||||
radio.openReadingPipe(1,0xE7E7E7E7E7LL);
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
}
|
||||
|
||||
//
|
||||
// Loop
|
||||
//
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Receive each packet, dump it out
|
||||
//
|
||||
|
||||
// if there is data ready
|
||||
if ( radio.available() )
|
||||
{
|
||||
// Get the packet from the radio
|
||||
payload_t payload;
|
||||
radio.read( &payload, sizeof(payload) );
|
||||
|
||||
// Print the ID of this message. Note that the message
|
||||
// is sent 'big-endian', so we have to flip it.
|
||||
printf("#%05u Buttons ",flip_endian(payload.id));
|
||||
|
||||
// Print the name of each button
|
||||
int i = num_buttons;
|
||||
while (i--)
|
||||
{
|
||||
if ( ! ( payload.buttons & _BV(i) ) )
|
||||
{
|
||||
printf("%s ",button_names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// If no buttons, print None
|
||||
if ( payload.buttons == _BV(num_buttons) - 1 )
|
||||
printf("None");
|
||||
|
||||
printf("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Helper functions
|
||||
//
|
||||
|
||||
// Change a big-endian word into a little-endian
|
||||
uint16_t flip_endian(uint16_t in)
|
||||
{
|
||||
uint16_t low = in >> 8;
|
||||
uint16_t high = in << 8;
|
||||
|
||||
return high | low;
|
||||
}
|
||||
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
||||
39
digistump-sam/libraries/RF24/examples/nordic_fob/printf.h
Normal file
39
digistump-sam/libraries/RF24/examples/nordic_fob/printf.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
219
digistump-sam/libraries/RF24/examples/pingpair/Jamfile
Normal file
219
digistump-sam/libraries/RF24/examples/pingpair/Jamfile
Normal file
@@ -0,0 +1,219 @@
|
||||
# (1) Project Information
|
||||
|
||||
PROJECT_LIBS = SPI RF24 ;
|
||||
PROJECT_DIRS = $(PWD) ;
|
||||
|
||||
# (2) Board Information
|
||||
|
||||
UPLOAD_PROTOCOL ?= arduino ;
|
||||
UPLOAD_SPEED ?= 115200 ;
|
||||
MCU ?= atmega328p ;
|
||||
F_CPU ?= 16000000 ;
|
||||
CORE ?= arduino ;
|
||||
VARIANT ?= standard ;
|
||||
ARDUINO_VERSION ?= 100 ;
|
||||
|
||||
# (3) USB Ports
|
||||
|
||||
PORTS = p4 p6 p9 u0 u1 u2 ;
|
||||
PORT_p6 = /dev/tty.usbserial-A600eHIs ;
|
||||
PORT_p4 = /dev/tty.usbserial-A40081RP ;
|
||||
PORT_p9 = /dev/tty.usbserial-A9007LmI ;
|
||||
PORT_u0 = /dev/ttyUSB0 ;
|
||||
PORT_u1 = /dev/ttyUSB1 ;
|
||||
PORT_u2 = /dev/ttyUSB2 ;
|
||||
|
||||
# (4) Location of AVR tools
|
||||
#
|
||||
# This configuration assumes using avr-tools that were obtained separate from the Arduino
|
||||
# distribution.
|
||||
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
AVR_BIN ?= /usr/local/avrtools/bin ;
|
||||
AVR_ETC = /usr/local/avrtools/etc ;
|
||||
AVR_INCLUDE = /usr/local/avrtools/include ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR_BIN ?= /usr/bin ;
|
||||
AVR_INCLUDE = /usr/lib/avr/include ;
|
||||
AVR_ETC = /etc ;
|
||||
}
|
||||
|
||||
# (5) Directories where Arduino core and libraries are located
|
||||
|
||||
ARDUINO_DIR ?= /opt/Arduino ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
|
||||
#
|
||||
# --------------------------------------------------
|
||||
# Below this line usually never needs to be modified
|
||||
#
|
||||
|
||||
# Tool locations
|
||||
|
||||
CC = $(AVR_BIN)/avr-gcc ;
|
||||
C++ = $(AVR_BIN)/avr-g++ ;
|
||||
LINK = $(AVR_BIN)/avr-gcc ;
|
||||
AR = $(AVR_BIN)/avr-ar rcs ;
|
||||
RANLIB = ;
|
||||
OBJCOPY = $(AVR_BIN)/avr-objcopy ;
|
||||
AVRDUDE ?= $(AVR_BIN)/avrdude ;
|
||||
|
||||
# Flags
|
||||
|
||||
DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
OPTIM = -Os ;
|
||||
CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ;
|
||||
C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ;
|
||||
LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ;
|
||||
AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ;
|
||||
|
||||
# Search everywhere for headers
|
||||
|
||||
HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ;
|
||||
|
||||
# Output locations
|
||||
|
||||
LOCATE_TARGET = $(F_CPU) ;
|
||||
LOCATE_SOURCE = $(F_CPU) ;
|
||||
|
||||
#
|
||||
# Custom rules
|
||||
#
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_SOURCE) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
if ( $(ARDUINO_VERSION) < 100 )
|
||||
{
|
||||
ARDUINO_H = WProgram.h ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ARDUINO_H = Arduino.h ;
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <$(ARDUINO_H)>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule C++Pde
|
||||
{
|
||||
local _CPP = $(>:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
C++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule UserObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .ino : C++Pde $(<) : $(>) ;
|
||||
case .pde : C++Pde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Objects
|
||||
{
|
||||
local _i ;
|
||||
|
||||
for _i in [ FGristFiles $(<) ]
|
||||
{
|
||||
local _b = $(_i:B)$(SUFOBJ) ;
|
||||
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
|
||||
Object $(_o) : $(_i) ;
|
||||
Depends obj : $(_o) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Library
|
||||
{
|
||||
LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Main
|
||||
{
|
||||
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Hex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions Hex
|
||||
{
|
||||
$(OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule Upload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
UploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions UploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
rule Arduino
|
||||
{
|
||||
LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ;
|
||||
Main $(<) : $(>) ;
|
||||
LinkLibraries $(<) : core libs ;
|
||||
Hex $(<:B).hex : $(<) ;
|
||||
for _p in $(PORTS)
|
||||
{
|
||||
Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Targets
|
||||
#
|
||||
|
||||
# Grab everything from the core directory
|
||||
Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ;
|
||||
|
||||
# Main output executable
|
||||
Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ;
|
||||
220
digistump-sam/libraries/RF24/examples/pingpair/pingpair.pde
Normal file
220
digistump-sam/libraries/RF24/examples/pingpair/pingpair.pde
Normal file
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example RF Radio Ping Pair
|
||||
*
|
||||
* This is an example of how to use the RF24 class. Write this sketch to two different nodes,
|
||||
* connect the role_pin to ground on one. The ping node sends the current time to the pong node,
|
||||
* which responds by sending the value back. The ping node can then see how long the whole cycle
|
||||
* took.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'ping' transmitter
|
||||
const int role_pin = 7;
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Radio pipe addresses for the 2 nodes to communicate.
|
||||
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes
|
||||
// in this system. Doing so greatly simplifies testing. The hardware itself specifies
|
||||
// which node it is.
|
||||
//
|
||||
// This is done through the role_pin
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_ping_out = 1, role_pong_back } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Role
|
||||
//
|
||||
|
||||
// set up the role pin
|
||||
pinMode(role_pin, INPUT);
|
||||
digitalWrite(role_pin,HIGH);
|
||||
delay(20); // Just to get a solid reading on the role pin
|
||||
|
||||
// read the address pin, establish our role
|
||||
if ( ! digitalRead(role_pin) )
|
||||
role = role_ping_out;
|
||||
else
|
||||
role = role_pong_back;
|
||||
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/pingpair/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
// optionally, increase the delay between retries & # of retries
|
||||
radio.setRetries(15,15);
|
||||
|
||||
// optionally, reduce the payload size. seems to
|
||||
// improve reliability
|
||||
radio.setPayloadSize(8);
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// This simple sketch opens two pipes for these two nodes to communicate
|
||||
// back and forth.
|
||||
// Open 'our' pipe for writing
|
||||
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
|
||||
|
||||
if ( role == role_ping_out )
|
||||
{
|
||||
radio.openWritingPipe(pipes[0]);
|
||||
radio.openReadingPipe(1,pipes[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
radio.openWritingPipe(pipes[1]);
|
||||
radio.openReadingPipe(1,pipes[0]);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Ping out role. Repeatedly send the current time
|
||||
//
|
||||
|
||||
if (role == role_ping_out)
|
||||
{
|
||||
// First, stop listening so we can talk.
|
||||
radio.stopListening();
|
||||
|
||||
// Take the time, and send it. This will block until complete
|
||||
unsigned long time = millis();
|
||||
printf("Now sending %lu...",time);
|
||||
bool ok = radio.write( &time, sizeof(unsigned long) );
|
||||
|
||||
if (ok)
|
||||
printf("ok...");
|
||||
else
|
||||
printf("failed.\n\r");
|
||||
|
||||
// Now, continue listening
|
||||
radio.startListening();
|
||||
|
||||
// Wait here until we get a response, or timeout (250ms)
|
||||
unsigned long started_waiting_at = millis();
|
||||
bool timeout = false;
|
||||
while ( ! radio.available() && ! timeout )
|
||||
if (millis() - started_waiting_at > 200 )
|
||||
timeout = true;
|
||||
|
||||
// Describe the results
|
||||
if ( timeout )
|
||||
{
|
||||
printf("Failed, response timed out.\n\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grab the response, compare, and send to debugging spew
|
||||
unsigned long got_time;
|
||||
radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
|
||||
}
|
||||
|
||||
// Try again 1s later
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
//
|
||||
// Pong back role. Receive each packet, dump it out, and send it back
|
||||
//
|
||||
|
||||
if ( role == role_pong_back )
|
||||
{
|
||||
// if there is data ready
|
||||
if ( radio.available() )
|
||||
{
|
||||
// Dump the payloads until we've gotten everything
|
||||
unsigned long got_time;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Fetch the payload, and see if this was the last one.
|
||||
done = radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got payload %lu...",got_time);
|
||||
|
||||
// Delay just a little bit to let the other unit
|
||||
// make the transition to receiver
|
||||
delay(20);
|
||||
}
|
||||
|
||||
// First, stop listening so we can talk
|
||||
radio.stopListening();
|
||||
|
||||
// Send the final one back.
|
||||
radio.write( &got_time, sizeof(unsigned long) );
|
||||
printf("Sent response.\n\r");
|
||||
|
||||
// Now, resume listening so we catch the next packets.
|
||||
radio.startListening();
|
||||
}
|
||||
}
|
||||
}
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
||||
39
digistump-sam/libraries/RF24/examples/pingpair/printf.h
Normal file
39
digistump-sam/libraries/RF24/examples/pingpair/printf.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
206
digistump-sam/libraries/RF24/examples/pingpair_dyn/Jamfile
Normal file
206
digistump-sam/libraries/RF24/examples/pingpair_dyn/Jamfile
Normal file
@@ -0,0 +1,206 @@
|
||||
PROJECT_NAME = $(PWD:B) ;
|
||||
PROJECT_DIR = . ;
|
||||
PROJECT_LIBS = SPI RF24 ;
|
||||
|
||||
OUT_DIR = ojam ;
|
||||
F_CPU = 16000000 ;
|
||||
MCU = atmega328p ;
|
||||
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
|
||||
|
||||
UPLOAD_RATE = 57600 ;
|
||||
AVRDUDE_PROTOCOL = stk500v1 ;
|
||||
COM = 33 ;
|
||||
|
||||
# Host-specific overrides for locations
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
ARDUINO_VERSION = 22 ;
|
||||
OLD_DIR = /opt/arduino-0021 ;
|
||||
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
|
||||
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
|
||||
ARDUINO_DIR = /opt/Arduino ;
|
||||
ARDUINO_AVR = /usr/lib/avr/include ;
|
||||
}
|
||||
|
||||
# Where is everything?
|
||||
ARDUINO_VERSION ?= 22 ;
|
||||
AVR_TOOLS_PATH ?= /usr/bin ;
|
||||
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
|
||||
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
|
||||
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
|
||||
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
|
||||
|
||||
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
CTUNING = -ffunction-sections -fdata-sections ;
|
||||
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
|
||||
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
|
||||
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
|
||||
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
|
||||
|
||||
# Search everywhere for headers
|
||||
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
|
||||
|
||||
# Grab everything from the core directory
|
||||
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
|
||||
|
||||
# In addition to explicitly-specified program modules, pick up anything from the current
|
||||
# dir.
|
||||
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
|
||||
|
||||
# Shortcut for the out files
|
||||
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
|
||||
|
||||
# AvrDude setup
|
||||
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule AvrCc
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrCc
|
||||
{
|
||||
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule AvrC++
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrC++
|
||||
{
|
||||
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <WProgram.h>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule AvrPde
|
||||
{
|
||||
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
AvrC++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule AvrObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .c : AvrCc $(<) : $(>) ;
|
||||
case .cpp : AvrC++ $(<) : $(>) ;
|
||||
case .pde : AvrPde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrObjects
|
||||
{
|
||||
for _I in $(<)
|
||||
{
|
||||
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrMainFromObjects
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
MkDir $(<:D) ;
|
||||
Depends all : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrMainFromObjects
|
||||
{
|
||||
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
|
||||
}
|
||||
|
||||
rule AvrMain
|
||||
{
|
||||
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
|
||||
AvrObjects $(>) ;
|
||||
}
|
||||
|
||||
rule AvrHex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrHex
|
||||
{
|
||||
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule AvrUpload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
AvrUploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions AvrUploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
|
||||
AvrHex $(OUT).hex : $(OUT).elf ;
|
||||
|
||||
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
|
||||
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
|
||||
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example using Dynamic Payloads
|
||||
*
|
||||
* This is an example of how to use payloads of a varying (dynamic) size.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'ping' transmitter
|
||||
const int role_pin = 7;
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Radio pipe addresses for the 2 nodes to communicate.
|
||||
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes
|
||||
// in this system. Doing so greatly simplifies testing. The hardware itself specifies
|
||||
// which node it is.
|
||||
//
|
||||
// This is done through the role_pin
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_ping_out = 1, role_pong_back } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role;
|
||||
|
||||
//
|
||||
// Payload
|
||||
//
|
||||
|
||||
const int min_payload_size = 4;
|
||||
const int max_payload_size = 32;
|
||||
const int payload_size_increments_by = 2;
|
||||
int next_payload_size = min_payload_size;
|
||||
|
||||
char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Role
|
||||
//
|
||||
|
||||
// set up the role pin
|
||||
pinMode(role_pin, INPUT);
|
||||
digitalWrite(role_pin,HIGH);
|
||||
delay(20); // Just to get a solid reading on the role pin
|
||||
|
||||
// read the address pin, establish our role
|
||||
if ( digitalRead(role_pin) )
|
||||
role = role_ping_out;
|
||||
else
|
||||
role = role_pong_back;
|
||||
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/pingpair_dyn/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
// enable dynamic payloads
|
||||
radio.enableDynamicPayloads();
|
||||
|
||||
// optionally, increase the delay between retries & # of retries
|
||||
radio.setRetries(15,15);
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// This simple sketch opens two pipes for these two nodes to communicate
|
||||
// back and forth.
|
||||
// Open 'our' pipe for writing
|
||||
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
|
||||
|
||||
if ( role == role_ping_out )
|
||||
{
|
||||
radio.openWritingPipe(pipes[0]);
|
||||
radio.openReadingPipe(1,pipes[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
radio.openWritingPipe(pipes[1]);
|
||||
radio.openReadingPipe(1,pipes[0]);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Ping out role. Repeatedly send the current time
|
||||
//
|
||||
|
||||
if (role == role_ping_out)
|
||||
{
|
||||
// The payload will always be the same, what will change is how much of it we send.
|
||||
static char send_payload[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ789012";
|
||||
|
||||
// First, stop listening so we can talk.
|
||||
radio.stopListening();
|
||||
|
||||
// Take the time, and send it. This will block until complete
|
||||
printf("Now sending length %i...",next_payload_size);
|
||||
radio.write( send_payload, next_payload_size );
|
||||
|
||||
// Now, continue listening
|
||||
radio.startListening();
|
||||
|
||||
// Wait here until we get a response, or timeout
|
||||
unsigned long started_waiting_at = millis();
|
||||
bool timeout = false;
|
||||
while ( ! radio.available() && ! timeout )
|
||||
if (millis() - started_waiting_at > 500 )
|
||||
timeout = true;
|
||||
|
||||
// Describe the results
|
||||
if ( timeout )
|
||||
{
|
||||
printf("Failed, response timed out.\n\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grab the response, compare, and send to debugging spew
|
||||
uint8_t len = radio.getDynamicPayloadSize();
|
||||
radio.read( receive_payload, len );
|
||||
|
||||
// Put a zero at the end for easy printing
|
||||
receive_payload[len] = 0;
|
||||
|
||||
// Spew it
|
||||
printf("Got response size=%i value=%s\n\r",len,receive_payload);
|
||||
}
|
||||
|
||||
// Update size for next time.
|
||||
next_payload_size += payload_size_increments_by;
|
||||
if ( next_payload_size > max_payload_size )
|
||||
next_payload_size = min_payload_size;
|
||||
|
||||
// Try again 1s later
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
//
|
||||
// Pong back role. Receive each packet, dump it out, and send it back
|
||||
//
|
||||
|
||||
if ( role == role_pong_back )
|
||||
{
|
||||
// if there is data ready
|
||||
if ( radio.available() )
|
||||
{
|
||||
// Dump the payloads until we've gotten everything
|
||||
uint8_t len;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Fetch the payload, and see if this was the last one.
|
||||
len = radio.getDynamicPayloadSize();
|
||||
done = radio.read( receive_payload, len );
|
||||
|
||||
// Put a zero at the end for easy printing
|
||||
receive_payload[len] = 0;
|
||||
|
||||
// Spew it
|
||||
printf("Got payload size=%i value=%s\n\r",len,receive_payload);
|
||||
}
|
||||
|
||||
// First, stop listening so we can talk
|
||||
radio.stopListening();
|
||||
|
||||
// Send the final one back.
|
||||
radio.write( receive_payload, len );
|
||||
printf("Sent response.\n\r");
|
||||
|
||||
// Now, resume listening so we catch the next packets.
|
||||
radio.startListening();
|
||||
}
|
||||
}
|
||||
}
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
||||
39
digistump-sam/libraries/RF24/examples/pingpair_dyn/printf.h
Normal file
39
digistump-sam/libraries/RF24/examples/pingpair_dyn/printf.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
219
digistump-sam/libraries/RF24/examples/pingpair_irq/Jamfile
Normal file
219
digistump-sam/libraries/RF24/examples/pingpair_irq/Jamfile
Normal file
@@ -0,0 +1,219 @@
|
||||
# (1) Project Information
|
||||
|
||||
PROJECT_LIBS = SPI RF24 ;
|
||||
PROJECT_DIRS = $(PWD) ;
|
||||
|
||||
# (2) Board Information
|
||||
|
||||
UPLOAD_PROTOCOL ?= arduino ;
|
||||
UPLOAD_SPEED ?= 115200 ;
|
||||
MCU ?= atmega328p ;
|
||||
F_CPU ?= 16000000 ;
|
||||
CORE ?= arduino ;
|
||||
VARIANT ?= standard ;
|
||||
ARDUINO_VERSION ?= 100 ;
|
||||
|
||||
# (3) USB Ports
|
||||
|
||||
PORTS = p4 p6 p9 u0 u1 u2 ;
|
||||
PORT_p6 = /dev/tty.usbserial-A600eHIs ;
|
||||
PORT_p4 = /dev/tty.usbserial-A40081RP ;
|
||||
PORT_p9 = /dev/tty.usbserial-A9007LmI ;
|
||||
PORT_u0 = /dev/ttyUSB0 ;
|
||||
PORT_u1 = /dev/ttyUSB1 ;
|
||||
PORT_u2 = /dev/ttyUSB2 ;
|
||||
|
||||
# (4) Location of AVR tools
|
||||
#
|
||||
# This configuration assumes using avr-tools that were obtained separate from the Arduino
|
||||
# distribution.
|
||||
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
AVR_BIN ?= /usr/local/avrtools/bin ;
|
||||
AVR_ETC = /usr/local/avrtools/etc ;
|
||||
AVR_INCLUDE = /usr/local/avrtools/include ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR_BIN ?= /usr/bin ;
|
||||
AVR_INCLUDE ?= /usr/lib/avr/include ;
|
||||
AVR_ETC = /etc ;
|
||||
}
|
||||
|
||||
# (5) Directories where Arduino core and libraries are located
|
||||
|
||||
ARDUINO_DIR ?= /opt/Arduino ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
|
||||
#
|
||||
# --------------------------------------------------
|
||||
# Below this line usually never needs to be modified
|
||||
#
|
||||
|
||||
# Tool locations
|
||||
|
||||
CC = $(AVR_BIN)/avr-gcc ;
|
||||
C++ = $(AVR_BIN)/avr-g++ ;
|
||||
LINK = $(AVR_BIN)/avr-gcc ;
|
||||
AR = $(AVR_BIN)/avr-ar rcs ;
|
||||
RANLIB = ;
|
||||
OBJCOPY = $(AVR_BIN)/avr-objcopy ;
|
||||
AVRDUDE ?= $(AVR_BIN)/avrdude ;
|
||||
|
||||
# Flags
|
||||
|
||||
DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
OPTIM = -Os ;
|
||||
CCFLAGS = -Wall -Wextra -Wno-strict-aliasing -mmcu=$(MCU) -ffunction-sections -fdata-sections ;
|
||||
C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ;
|
||||
LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ;
|
||||
AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ;
|
||||
|
||||
# Search everywhere for headers
|
||||
|
||||
HDRS = $(PROJECT_DIRS) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ;
|
||||
|
||||
# Output locations
|
||||
|
||||
LOCATE_TARGET = $(F_CPU) ;
|
||||
LOCATE_SOURCE = $(F_CPU) ;
|
||||
|
||||
#
|
||||
# Custom rules
|
||||
#
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_SOURCE) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
if ( $(ARDUINO_VERSION) < 100 )
|
||||
{
|
||||
ARDUINO_H = WProgram.h ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ARDUINO_H = Arduino.h ;
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <$(ARDUINO_H)>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule C++Pde
|
||||
{
|
||||
local _CPP = $(>:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
C++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule UserObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .ino : C++Pde $(<) : $(>) ;
|
||||
case .pde : C++Pde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Objects
|
||||
{
|
||||
local _i ;
|
||||
|
||||
for _i in [ FGristFiles $(<) ]
|
||||
{
|
||||
local _b = $(_i:B)$(SUFOBJ) ;
|
||||
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
|
||||
Object $(_o) : $(_i) ;
|
||||
Depends obj : $(_o) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Library
|
||||
{
|
||||
LibraryFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Main
|
||||
{
|
||||
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Hex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions Hex
|
||||
{
|
||||
$(OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule Upload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
UploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions UploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
rule Arduino
|
||||
{
|
||||
LINKFLAGS on $(<) = $(LINKFLAGS) -Wl,-Map=$(LOCATE_TARGET)/$(<:B).map ;
|
||||
Main $(<) : $(>) ;
|
||||
LinkLibraries $(<) : core libs ;
|
||||
Hex $(<:B).hex : $(<) ;
|
||||
for _p in $(PORTS)
|
||||
{
|
||||
Upload $(_p) : $(PORT_$(_p)) : $(<:B).hex ;
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Targets
|
||||
#
|
||||
|
||||
# Grab everything from the core directory
|
||||
Library core : [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
Library libs : [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ;
|
||||
|
||||
# Main output executable
|
||||
Arduino $(PWD:B).elf : $(PROJECT_MODULES) [ GLOB $(PROJECT_DIRS) : *.c *.cpp *.pde *.ino ] ;
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example of using interrupts
|
||||
*
|
||||
* This is an example of how to user interrupts to interact with the radio.
|
||||
* It builds on the pingpair_pl example, and uses ack payloads.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(8,9);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'ping' transmitter
|
||||
const short role_pin = 7;
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Single radio pipe address for the 2 nodes to communicate.
|
||||
const uint64_t pipe = 0xE8E8F0F0E1LL;
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes in this
|
||||
// system. Doing so greatly simplifies testing. The hardware itself specifies
|
||||
// which node it is.
|
||||
//
|
||||
// This is done through the role_pin
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_sender = 1, role_receiver } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role;
|
||||
|
||||
// Interrupt handler, check the radio because we got an IRQ
|
||||
void check_radio(void);
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Role
|
||||
//
|
||||
|
||||
// set up the role pin
|
||||
pinMode(role_pin, INPUT);
|
||||
digitalWrite(role_pin,HIGH);
|
||||
delay(20); // Just to get a solid reading on the role pin
|
||||
|
||||
// read the address pin, establish our role
|
||||
if ( digitalRead(role_pin) )
|
||||
role = role_sender;
|
||||
else
|
||||
role = role_receiver;
|
||||
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/pingpair_irq/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
// We will be using the Ack Payload feature, so please enable it
|
||||
radio.enableAckPayload();
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// This simple sketch opens a single pipe for these two nodes to communicate
|
||||
// back and forth. One listens on it, the other talks to it.
|
||||
|
||||
if ( role == role_sender )
|
||||
{
|
||||
radio.openWritingPipe(pipe);
|
||||
}
|
||||
else
|
||||
{
|
||||
radio.openReadingPipe(1,pipe);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
if ( role == role_receiver )
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
|
||||
//
|
||||
// Attach interrupt handler to interrupt #0 (using pin 2)
|
||||
// on BOTH the sender and receiver
|
||||
//
|
||||
|
||||
attachInterrupt(0, check_radio, FALLING);
|
||||
}
|
||||
|
||||
static uint32_t message_count = 0;
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Sender role. Repeatedly send the current time
|
||||
//
|
||||
|
||||
if (role == role_sender)
|
||||
{
|
||||
// Take the time, and send it.
|
||||
unsigned long time = millis();
|
||||
printf("Now sending %lu\n\r",time);
|
||||
radio.startWrite( &time, sizeof(unsigned long) );
|
||||
|
||||
// Try again soon
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
//
|
||||
// Receiver role: Does nothing! All the work is in IRQ
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
void check_radio(void)
|
||||
{
|
||||
// What happened?
|
||||
bool tx,fail,rx;
|
||||
radio.whatHappened(tx,fail,rx);
|
||||
|
||||
// Have we successfully transmitted?
|
||||
if ( tx )
|
||||
{
|
||||
if ( role == role_sender )
|
||||
printf("Send:OK\n\r");
|
||||
|
||||
if ( role == role_receiver )
|
||||
printf("Ack Payload:Sent\n\r");
|
||||
}
|
||||
|
||||
// Have we failed to transmit?
|
||||
if ( fail )
|
||||
{
|
||||
if ( role == role_sender )
|
||||
printf("Send:Failed\n\r");
|
||||
|
||||
if ( role == role_receiver )
|
||||
printf("Ack Payload:Failed\n\r");
|
||||
}
|
||||
|
||||
// Transmitter can power down for now, because
|
||||
// the transmission is done.
|
||||
if ( ( tx || fail ) && ( role == role_sender ) )
|
||||
radio.powerDown();
|
||||
|
||||
// Did we receive a message?
|
||||
if ( rx )
|
||||
{
|
||||
// If we're the sender, we've received an ack payload
|
||||
if ( role == role_sender )
|
||||
{
|
||||
radio.read(&message_count,sizeof(message_count));
|
||||
printf("Ack:%lu\n\r",message_count);
|
||||
}
|
||||
|
||||
// If we're the receiver, we've received a time message
|
||||
if ( role == role_receiver )
|
||||
{
|
||||
// Get this payload and dump it
|
||||
static unsigned long got_time;
|
||||
radio.read( &got_time, sizeof(got_time) );
|
||||
printf("Got payload %lu\n\r",got_time);
|
||||
|
||||
// Add an ack packet for the next time around. This is a simple
|
||||
// packet counter
|
||||
radio.writeAckPayload( 1, &message_count, sizeof(message_count) );
|
||||
++message_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
39
digistump-sam/libraries/RF24/examples/pingpair_irq/printf.h
Normal file
39
digistump-sam/libraries/RF24/examples/pingpair_irq/printf.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
182
digistump-sam/libraries/RF24/examples/pingpair_maple/Jamfile
Normal file
182
digistump-sam/libraries/RF24/examples/pingpair_maple/Jamfile
Normal file
@@ -0,0 +1,182 @@
|
||||
MCU = cortex-m3 ;
|
||||
CHIP = STM32F103ZE ;
|
||||
BOARD = maple_native ;
|
||||
|
||||
#CHIP = at91sam3u4 ;
|
||||
#BOARD = sam3u-ek ;
|
||||
|
||||
if ! $(TOOLSET)
|
||||
{
|
||||
TOOLSET = devkit ;
|
||||
Echo "Assuming TOOLSET=devkit" ;
|
||||
}
|
||||
|
||||
if $(TOOLSET) = yagarto
|
||||
{
|
||||
TOOLS_PATH = ~/Source/yagarto-4.6.2/bin ;
|
||||
TOOLS_ARCH = arm-none-eabi- ;
|
||||
}
|
||||
if $(TOOLSET) = yagarto-install
|
||||
{
|
||||
TOOLS_PATH = ~/Source/yagarto/install/bin ;
|
||||
TOOLS_ARCH = arm-none-eabi- ;
|
||||
}
|
||||
else if $(TOOLSET) = devkit
|
||||
{
|
||||
TOOLS_PATH = /opt/devkitARM/bin ;
|
||||
TOOLS_ARCH = arm-eabi- ;
|
||||
}
|
||||
else if $(TOOLSET) = maple
|
||||
{
|
||||
TOOLS_PATH = /opt/Maple/Resources/Java/hardware/tools/arm/bin ;
|
||||
TOOLS_ARCH = arm-none-eabi- ;
|
||||
}
|
||||
else if $(TOOLSET) = ports
|
||||
{
|
||||
TOOLS_PATH = /opt/local/bin ;
|
||||
TOOLS_ARCH = arm-none-eabi- ;
|
||||
}
|
||||
|
||||
CC = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc ;
|
||||
C++ = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ;
|
||||
AS = $(TOOLS_PATH)/$(TOOLS_ARCH)gcc -c ;
|
||||
LINK = $(TOOLS_PATH)/$(TOOLS_ARCH)g++ ;
|
||||
OBJCOPY = $(TOOLS_PATH)/$(TOOLS_ARCH)objcopy ;
|
||||
DFU = dfu-util ;
|
||||
|
||||
DEFINES += VECT_TAB_FLASH BOARD_$(BOARD) MCU_$(CHIP) ERROR_LED_PORT=GPIOC ERROR_LED_PIN=15 STM32_HIGH_DENSITY MAPLE_IDE ;
|
||||
OPTIM = -Os ;
|
||||
MFLAGS = cpu=$(MCU) thumb arch=armv7-m ;
|
||||
CCFLAGS = -Wall -m$(MFLAGS) -g -nostdlib -ffunction-sections -fdata-sections -Wl,--gc-sections ;
|
||||
C++FLAGS = $(CCFLAGS) -fno-rtti -fno-exceptions ;
|
||||
LINKFLAGS += -m$(MFLAGS) -Xlinker --gc-sections ;
|
||||
DFUFLAGS = -a1 -d 0x1eaf:0x0003 -R ;
|
||||
|
||||
MAPLE_DIR = $(HOME)/Source/SAM3U/libmaple ;
|
||||
MAPLE_LIBS = Servo LiquidCrystal Wire FreeRTOS ;
|
||||
MAPLE_SUBDIRS = wirish wirish/comm wirish/boards libmaple libmaple/usb libmaple/usb/usb_lib ;
|
||||
|
||||
SKETCH_DIR = $(HOME)/Source/Arduino ;
|
||||
SKETCH_LIBS = RF24 ;
|
||||
|
||||
MODULE_DIRS = . $(MAPLE_DIR)/$(MAPLE_SUBDIRS) $(MAPLE_DIR)/libraries/$(MAPLE_LIBS) $(SKETCH_DIR)/libraries/$(SKETCH_LIBS) ;
|
||||
HDRS = $(MODULE_DIRS) ;
|
||||
LOCATE_TARGET = out/$(TOOLSET) ;
|
||||
LOCATE_SOURCE = $(LOCATE_TARGET) ;
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_SOURCE) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
if ( $(ARDUINO_VERSION) < 100 )
|
||||
{
|
||||
ARDUINO_H = WProgram.h ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ARDUINO_H = Arduino.h ;
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <$(ARDUINO_H)>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule C++Pde
|
||||
{
|
||||
local _CPP = $(>:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
C++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule Hex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions Hex
|
||||
{
|
||||
$(OBJCOPY) -O ihex $(>) $(<)
|
||||
}
|
||||
|
||||
rule Binary
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
Depends binary : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions Binary
|
||||
{
|
||||
$(OBJCOPY) -O binary $(>) $(<)
|
||||
}
|
||||
|
||||
rule UserObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .S : As $(<) : $(>) ;
|
||||
case .ino : C++Pde $(<) : $(>) ;
|
||||
case .pde : C++Pde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Upload
|
||||
{
|
||||
Depends up : $(<) ;
|
||||
NotFile up ;
|
||||
Always $(<) ;
|
||||
Always up ;
|
||||
}
|
||||
|
||||
actions Upload
|
||||
{
|
||||
$(DFU) $(DFUFLAGS) -D $(<)
|
||||
}
|
||||
|
||||
# Override base objects rule, so all output can go in the output dir
|
||||
rule Objects
|
||||
{
|
||||
local _i ;
|
||||
|
||||
for _i in [ FGristFiles $(<) ]
|
||||
{
|
||||
local _b = $(_i:B)$(SUFOBJ) ;
|
||||
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
|
||||
Object $(_o) : $(_i) ;
|
||||
Depends obj : $(_o) ;
|
||||
}
|
||||
}
|
||||
|
||||
# Override base main rule, so all output can go in the output dir
|
||||
rule Main
|
||||
{
|
||||
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
# Modules
|
||||
MODULES = [ GLOB $(MODULE_DIRS) : *.pde *.c *.cpp *.S ] ;
|
||||
|
||||
# Main output executable
|
||||
MAIN = $(PWD:B).elf ;
|
||||
|
||||
# Linker script
|
||||
LINK_DIR = $(MAPLE_DIR)/support/ld ;
|
||||
LINKSCRIPT = $(LINK_DIR)/$(BOARD)/flash.ld ;
|
||||
|
||||
# Bring in the map and link script
|
||||
LINKFLAGS += -Wl,-Map=$(LOCATE_TARGET)/$(MAIN:B).map -T$(LINKSCRIPT) -L$(LINK_DIR) ;
|
||||
|
||||
Main $(MAIN) : $(MODULES) ;
|
||||
Binary $(MAIN:B).bin : $(MAIN) ;
|
||||
Upload $(MAIN:B).bin ;
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifdef MAPLE_IDE
|
||||
|
||||
#include <stdio.h>
|
||||
#include "wirish.h"
|
||||
|
||||
extern void setup(void);
|
||||
extern void loop(void);
|
||||
|
||||
void board_start(const char* program_name)
|
||||
{
|
||||
// Set up the LED to steady on
|
||||
pinMode(BOARD_LED_PIN, OUTPUT);
|
||||
digitalWrite(BOARD_LED_PIN, HIGH);
|
||||
|
||||
// Setup the button as input
|
||||
pinMode(BOARD_BUTTON_PIN, INPUT);
|
||||
digitalWrite(BOARD_BUTTON_PIN, HIGH);
|
||||
|
||||
SerialUSB.begin();
|
||||
SerialUSB.println("Press BUT");
|
||||
|
||||
// Wait for button press
|
||||
while ( !isButtonPressed() )
|
||||
{
|
||||
}
|
||||
|
||||
SerialUSB.println("Welcome!");
|
||||
SerialUSB.println(program_name);
|
||||
|
||||
int i = 11;
|
||||
while (i--)
|
||||
{
|
||||
toggleLED();
|
||||
delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom version of _write, which will print to the USB.
|
||||
* In order to use it you MUST ADD __attribute__((weak))
|
||||
* to _write in libmaple/syscalls.c
|
||||
*/
|
||||
extern "C" int _write (int file, char * ptr, int len)
|
||||
{
|
||||
if ( (file != 1) && (file != 2) )
|
||||
return 0;
|
||||
else
|
||||
SerialUSB.write(ptr,len);
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-entrant version of _write. Yagarto and Devkit now use
|
||||
* the re-entrant newlib, so these get called instead of the
|
||||
* non_r versions.
|
||||
*/
|
||||
extern "C" int _write_r (void*, int file, char * ptr, int len)
|
||||
{
|
||||
return _write( file, ptr, len);
|
||||
}
|
||||
|
||||
__attribute__((constructor)) __attribute__ ((weak)) void premain()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
__attribute__((weak)) void setup(void)
|
||||
{
|
||||
board_start("No program defined");
|
||||
}
|
||||
|
||||
__attribute__((weak)) void loop(void)
|
||||
{
|
||||
}
|
||||
|
||||
__attribute__((weak)) int main(void)
|
||||
{
|
||||
setup();
|
||||
|
||||
while (true)
|
||||
{
|
||||
loop();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif // ifdef MAPLE_IDE
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example RF Radio Ping Pair ... for Maple
|
||||
*
|
||||
* This is an example of how to use the RF24 class. Write this sketch to two different nodes,
|
||||
* connect the role_pin to ground on one. The ping node sends the current time to the pong node,
|
||||
* which responds by sending the value back. The ping node can then see how long the whole cycle
|
||||
* took.
|
||||
*/
|
||||
|
||||
#include "WProgram.h"
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
|
||||
//
|
||||
// Maple specific setup. Other than this section, the sketch is the same on Maple as on
|
||||
// Arduino
|
||||
//
|
||||
|
||||
#ifdef MAPLE_IDE
|
||||
|
||||
// External startup function
|
||||
extern void board_start(const char* program_name);
|
||||
|
||||
// Use SPI #2.
|
||||
HardwareSPI SPI(2);
|
||||
|
||||
#else
|
||||
#define board_startup printf
|
||||
#define toggleLED(x) (x)
|
||||
#endif
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 7 & 6
|
||||
// (This works for the Getting Started board plugged into the
|
||||
// Maple Native backwards.)
|
||||
|
||||
RF24 radio(7,6);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'ping' transmitter
|
||||
const int role_pin = 10;
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Radio pipe addresses for the 2 nodes to communicate.
|
||||
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes
|
||||
// in this system. Doing so greatly simplifies testing. The hardware itself specifies
|
||||
// which node it is.
|
||||
//
|
||||
// This is done through the role_pin
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_ping_out = 1, role_pong_back } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Role
|
||||
//
|
||||
|
||||
// set up the role pin
|
||||
pinMode(role_pin, INPUT);
|
||||
digitalWrite(role_pin,HIGH);
|
||||
delay(20); // Just to get a solid reading on the role pin
|
||||
|
||||
// read the address pin, establish our role
|
||||
if ( digitalRead(role_pin) )
|
||||
role = role_ping_out;
|
||||
else
|
||||
role = role_pong_back;
|
||||
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
board_start("\n\rRF24/examples/pingpair/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
// optionally, increase the delay between retries & # of retries
|
||||
radio.setRetries(15,15);
|
||||
|
||||
// optionally, reduce the payload size. seems to
|
||||
// improve reliability
|
||||
radio.setPayloadSize(8);
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// This simple sketch opens two pipes for these two nodes to communicate
|
||||
// back and forth.
|
||||
// Open 'our' pipe for writing
|
||||
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
|
||||
|
||||
if ( role == role_ping_out )
|
||||
{
|
||||
radio.openWritingPipe(pipes[0]);
|
||||
radio.openReadingPipe(1,pipes[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
radio.openWritingPipe(pipes[1]);
|
||||
radio.openReadingPipe(1,pipes[0]);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Ping out role. Repeatedly send the current time
|
||||
//
|
||||
|
||||
if (role == role_ping_out)
|
||||
{
|
||||
toggleLED();
|
||||
|
||||
// First, stop listening so we can talk.
|
||||
radio.stopListening();
|
||||
|
||||
// Take the time, and send it. This will block until complete
|
||||
unsigned long time = millis();
|
||||
printf("Now sending %lu...",time);
|
||||
bool ok = radio.write( &time, sizeof(unsigned long) );
|
||||
|
||||
if (ok)
|
||||
printf("ok...\r\n");
|
||||
else
|
||||
printf("failed.\r\n");
|
||||
|
||||
// Now, continue listening
|
||||
radio.startListening();
|
||||
|
||||
// Wait here until we get a response, or timeout (250ms)
|
||||
unsigned long started_waiting_at = millis();
|
||||
bool timeout = false;
|
||||
while ( ! radio.available() && ! timeout )
|
||||
if (millis() - started_waiting_at > 200 )
|
||||
timeout = true;
|
||||
|
||||
// Describe the results
|
||||
if ( timeout )
|
||||
{
|
||||
printf("Failed, response timed out.\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grab the response, compare, and send to debugging spew
|
||||
unsigned long got_time;
|
||||
radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got response %lu, round-trip delay: %lu\r\n",got_time,millis()-got_time);
|
||||
}
|
||||
|
||||
toggleLED();
|
||||
|
||||
// Try again 1s later
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
//
|
||||
// Pong back role. Receive each packet, dump it out, and send it back
|
||||
//
|
||||
|
||||
if ( role == role_pong_back )
|
||||
{
|
||||
// if there is data ready
|
||||
if ( radio.available() )
|
||||
{
|
||||
// Dump the payloads until we've gotten everything
|
||||
unsigned long got_time;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Fetch the payload, and see if this was the last one.
|
||||
done = radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got payload %lu...",got_time);
|
||||
|
||||
// Delay just a little bit to let the other unit
|
||||
// make the transition to receiver
|
||||
delay(20);
|
||||
}
|
||||
|
||||
// First, stop listening so we can talk
|
||||
radio.stopListening();
|
||||
|
||||
// Send the final one back.
|
||||
radio.write( &got_time, sizeof(unsigned long) );
|
||||
printf("Sent response.\r\n");
|
||||
|
||||
// Now, resume listening so we catch the next packets.
|
||||
radio.startListening();
|
||||
}
|
||||
}
|
||||
}
|
||||
// vim:cin:ai:sts=2 sw=2 ft=cpp
|
||||
206
digistump-sam/libraries/RF24/examples/pingpair_pl/Jamfile
Normal file
206
digistump-sam/libraries/RF24/examples/pingpair_pl/Jamfile
Normal file
@@ -0,0 +1,206 @@
|
||||
PROJECT_NAME = $(PWD:B) ;
|
||||
PROJECT_DIR = . ;
|
||||
PROJECT_LIBS = SPI RF24 ;
|
||||
|
||||
OUT_DIR = ojam ;
|
||||
F_CPU = 16000000 ;
|
||||
MCU = atmega328p ;
|
||||
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
|
||||
|
||||
UPLOAD_RATE = 57600 ;
|
||||
AVRDUDE_PROTOCOL = stk500v1 ;
|
||||
COM = 33 ;
|
||||
|
||||
# Host-specific overrides for locations
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
ARDUINO_VERSION = 22 ;
|
||||
OLD_DIR = /opt/arduino-0021 ;
|
||||
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
|
||||
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
|
||||
ARDUINO_DIR = /opt/Arduino ;
|
||||
ARDUINO_AVR = /usr/lib/avr/include ;
|
||||
}
|
||||
|
||||
# Where is everything?
|
||||
ARDUINO_VERSION ?= 22 ;
|
||||
AVR_TOOLS_PATH ?= /usr/bin ;
|
||||
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
|
||||
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
|
||||
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
|
||||
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
|
||||
|
||||
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
CTUNING = -ffunction-sections -fdata-sections ;
|
||||
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
|
||||
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
|
||||
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
|
||||
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
|
||||
|
||||
# Search everywhere for headers
|
||||
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
|
||||
|
||||
# Grab everything from the core directory
|
||||
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
|
||||
|
||||
# In addition to explicitly-specified program modules, pick up anything from the current
|
||||
# dir.
|
||||
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
|
||||
|
||||
# Shortcut for the out files
|
||||
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
|
||||
|
||||
# AvrDude setup
|
||||
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule AvrCc
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrCc
|
||||
{
|
||||
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule AvrC++
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrC++
|
||||
{
|
||||
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <WProgram.h>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule AvrPde
|
||||
{
|
||||
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
AvrC++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule AvrObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .c : AvrCc $(<) : $(>) ;
|
||||
case .cpp : AvrC++ $(<) : $(>) ;
|
||||
case .pde : AvrPde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrObjects
|
||||
{
|
||||
for _I in $(<)
|
||||
{
|
||||
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrMainFromObjects
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
MkDir $(<:D) ;
|
||||
Depends all : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrMainFromObjects
|
||||
{
|
||||
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
|
||||
}
|
||||
|
||||
rule AvrMain
|
||||
{
|
||||
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
|
||||
AvrObjects $(>) ;
|
||||
}
|
||||
|
||||
rule AvrHex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrHex
|
||||
{
|
||||
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule AvrUpload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
AvrUploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions AvrUploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
|
||||
AvrHex $(OUT).hex : $(OUT).elf ;
|
||||
|
||||
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
|
||||
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
|
||||
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example of using Ack Payloads
|
||||
*
|
||||
* This is an example of how to do two-way communication without changing
|
||||
* transmit/receive modes. Here, a payload is set to the transmitter within
|
||||
* the Ack packet of each transmission. Note that the payload is set BEFORE
|
||||
* the sender's message arrives.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'ping' transmitter
|
||||
const short role_pin = 7;
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Single radio pipe address for the 2 nodes to communicate.
|
||||
const uint64_t pipe = 0xE8E8F0F0E1LL;
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes in this
|
||||
// system. Doing so greatly simplifies testing. The hardware itself specifies
|
||||
// which node it is.
|
||||
//
|
||||
// This is done through the role_pin
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_sender = 1, role_receiver } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Sender", "Receiver"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Role
|
||||
//
|
||||
|
||||
// set up the role pin
|
||||
pinMode(role_pin, INPUT);
|
||||
digitalWrite(role_pin,HIGH);
|
||||
delay(20); // Just to get a solid reading on the role pin
|
||||
|
||||
// read the address pin, establish our role
|
||||
if ( digitalRead(role_pin) )
|
||||
role = role_sender;
|
||||
else
|
||||
role = role_receiver;
|
||||
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/pingpair_pl/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
// We will be using the Ack Payload feature, so please enable it
|
||||
radio.enableAckPayload();
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// This simple sketch opens a single pipes for these two nodes to communicate
|
||||
// back and forth. One listens on it, the other talks to it.
|
||||
|
||||
if ( role == role_sender )
|
||||
{
|
||||
radio.openWritingPipe(pipe);
|
||||
}
|
||||
else
|
||||
{
|
||||
radio.openReadingPipe(1,pipe);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
if ( role == role_receiver )
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
static uint32_t message_count = 0;
|
||||
|
||||
//
|
||||
// Sender role. Repeatedly send the current time
|
||||
//
|
||||
|
||||
if (role == role_sender)
|
||||
{
|
||||
// Take the time, and send it. This will block until complete
|
||||
unsigned long time = millis();
|
||||
printf("Now sending %lu...",time);
|
||||
radio.write( &time, sizeof(unsigned long) );
|
||||
|
||||
if ( radio.isAckPayloadAvailable() )
|
||||
{
|
||||
radio.read(&message_count,sizeof(message_count));
|
||||
printf("Ack: [%lu] ",message_count);
|
||||
}
|
||||
printf("OK\n\r");
|
||||
|
||||
// Try again soon
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
//
|
||||
// Receiver role. Receive each packet, dump it out, add ack payload for next time
|
||||
//
|
||||
|
||||
if ( role == role_receiver )
|
||||
{
|
||||
// if there is data ready
|
||||
if ( radio.available() )
|
||||
{
|
||||
// Dump the payloads until we've gotten everything
|
||||
static unsigned long got_time;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Fetch the payload, and see if this was the last one.
|
||||
done = radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got payload %lu\n",got_time);
|
||||
}
|
||||
|
||||
// Add an ack packet for the next time around. This is a simple
|
||||
// packet counter
|
||||
radio.writeAckPayload( 1, &message_count, sizeof(message_count) );
|
||||
++message_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
39
digistump-sam/libraries/RF24/examples/pingpair_pl/printf.h
Normal file
39
digistump-sam/libraries/RF24/examples/pingpair_pl/printf.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
206
digistump-sam/libraries/RF24/examples/pingpair_sleepy/Jamfile
Normal file
206
digistump-sam/libraries/RF24/examples/pingpair_sleepy/Jamfile
Normal file
@@ -0,0 +1,206 @@
|
||||
PROJECT_NAME = $(PWD:B) ;
|
||||
PROJECT_DIR = . ;
|
||||
PROJECT_LIBS = SPI RF24 ;
|
||||
|
||||
OUT_DIR = ojam ;
|
||||
F_CPU = 16000000 ;
|
||||
MCU = atmega328p ;
|
||||
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
|
||||
|
||||
UPLOAD_RATE = 57600 ;
|
||||
AVRDUDE_PROTOCOL = stk500v1 ;
|
||||
COM = 33 ;
|
||||
|
||||
# Host-specific overrides for locations
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
ARDUINO_VERSION = 22 ;
|
||||
OLD_DIR = /opt/arduino-0021 ;
|
||||
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
|
||||
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
|
||||
ARDUINO_DIR = /opt/Arduino ;
|
||||
ARDUINO_AVR = /usr/lib/avr/include ;
|
||||
}
|
||||
|
||||
# Where is everything?
|
||||
ARDUINO_VERSION ?= 22 ;
|
||||
AVR_TOOLS_PATH ?= /usr/bin ;
|
||||
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
|
||||
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
|
||||
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
|
||||
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
|
||||
|
||||
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
CTUNING = -ffunction-sections -fdata-sections ;
|
||||
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
|
||||
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
|
||||
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
|
||||
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
|
||||
|
||||
# Search everywhere for headers
|
||||
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
|
||||
|
||||
# Grab everything from the core directory
|
||||
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
|
||||
|
||||
# In addition to explicitly-specified program modules, pick up anything from the current
|
||||
# dir.
|
||||
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
|
||||
|
||||
# Shortcut for the out files
|
||||
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
|
||||
|
||||
# AvrDude setup
|
||||
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule AvrCc
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrCc
|
||||
{
|
||||
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule AvrC++
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrC++
|
||||
{
|
||||
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <WProgram.h>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule AvrPde
|
||||
{
|
||||
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
AvrC++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule AvrObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .c : AvrCc $(<) : $(>) ;
|
||||
case .cpp : AvrC++ $(<) : $(>) ;
|
||||
case .pde : AvrPde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrObjects
|
||||
{
|
||||
for _I in $(<)
|
||||
{
|
||||
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrMainFromObjects
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
MkDir $(<:D) ;
|
||||
Depends all : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrMainFromObjects
|
||||
{
|
||||
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
|
||||
}
|
||||
|
||||
rule AvrMain
|
||||
{
|
||||
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
|
||||
AvrObjects $(>) ;
|
||||
}
|
||||
|
||||
rule AvrHex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrHex
|
||||
{
|
||||
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule AvrUpload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
AvrUploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions AvrUploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
|
||||
AvrHex $(OUT).hex : $(OUT).elf ;
|
||||
|
||||
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
|
||||
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
|
||||
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example RF Radio Ping Pair which Sleeps between Sends
|
||||
*
|
||||
* This is an example of how to use the RF24 class to create a battery-
|
||||
* efficient system. It is just like the pingpair.pde example, but the
|
||||
* ping node powers down the radio and sleeps the MCU after every
|
||||
* ping/pong cycle.
|
||||
*
|
||||
* As with the pingpair.pde example, write this sketch to two different nodes,
|
||||
* connect the role_pin to ground on one. The ping node sends the current
|
||||
* time to the pong node, which responds by sending the value back. The ping
|
||||
* node can then see how long the whole cycle took.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <avr/power.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'ping' transmitter
|
||||
const int role_pin = 7;
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Radio pipe addresses for the 2 nodes to communicate.
|
||||
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes
|
||||
// in this system. Doing so greatly simplifies testing. The hardware itself specifies
|
||||
// which node it is.
|
||||
//
|
||||
// This is done through the role_pin
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_ping_out = 1, role_pong_back } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role;
|
||||
|
||||
//
|
||||
// Sleep declarations
|
||||
//
|
||||
|
||||
typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s } wdt_prescalar_e;
|
||||
|
||||
void setup_watchdog(uint8_t prescalar);
|
||||
void do_sleep(void);
|
||||
|
||||
const short sleep_cycles_per_transmission = 4;
|
||||
volatile short sleep_cycles_remaining = sleep_cycles_per_transmission;
|
||||
|
||||
//
|
||||
// Normal operation
|
||||
//
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Role
|
||||
//
|
||||
|
||||
// set up the role pin
|
||||
pinMode(role_pin, INPUT);
|
||||
digitalWrite(role_pin,HIGH);
|
||||
delay(20); // Just to get a solid reading on the role pin
|
||||
|
||||
// read the address pin, establish our role
|
||||
if ( digitalRead(role_pin) )
|
||||
role = role_ping_out;
|
||||
else
|
||||
role = role_pong_back;
|
||||
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/pingpair_sleepy/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
|
||||
//
|
||||
// Prepare sleep parameters
|
||||
//
|
||||
|
||||
// Only the ping out role sleeps. Wake up every 4s to send a ping
|
||||
if ( role == role_ping_out )
|
||||
setup_watchdog(wdt_1s);
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// This simple sketch opens two pipes for these two nodes to communicate
|
||||
// back and forth.
|
||||
// Open 'our' pipe for writing
|
||||
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
|
||||
|
||||
if ( role == role_ping_out )
|
||||
{
|
||||
radio.openWritingPipe(pipes[0]);
|
||||
radio.openReadingPipe(1,pipes[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
radio.openWritingPipe(pipes[1]);
|
||||
radio.openReadingPipe(1,pipes[0]);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Ping out role. Repeatedly send the current time
|
||||
//
|
||||
|
||||
if (role == role_ping_out)
|
||||
{
|
||||
// First, stop listening so we can talk.
|
||||
radio.stopListening();
|
||||
|
||||
// Take the time, and send it. This will block until complete
|
||||
unsigned long time = millis();
|
||||
printf("Now sending %lu...",time);
|
||||
radio.write( &time, sizeof(unsigned long) );
|
||||
|
||||
// Now, continue listening
|
||||
radio.startListening();
|
||||
|
||||
// Wait here until we get a response, or timeout (250ms)
|
||||
unsigned long started_waiting_at = millis();
|
||||
bool timeout = false;
|
||||
while ( ! radio.available() && ! timeout )
|
||||
if (millis() - started_waiting_at > 250 )
|
||||
timeout = true;
|
||||
|
||||
// Describe the results
|
||||
if ( timeout )
|
||||
{
|
||||
printf("Failed, response timed out.\n\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grab the response, compare, and send to debugging spew
|
||||
unsigned long got_time;
|
||||
radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
|
||||
}
|
||||
|
||||
//
|
||||
// Shut down the system
|
||||
//
|
||||
|
||||
// Experiment with some delay here to see if it has an effect
|
||||
delay(500);
|
||||
|
||||
// Power down the radio. Note that the radio will get powered back up
|
||||
// on the next write() call.
|
||||
radio.powerDown();
|
||||
|
||||
// Sleep the MCU. The watchdog timer will awaken in a short while, and
|
||||
// continue execution here.
|
||||
while( sleep_cycles_remaining )
|
||||
do_sleep();
|
||||
|
||||
sleep_cycles_remaining = sleep_cycles_per_transmission;
|
||||
}
|
||||
|
||||
//
|
||||
// Pong back role. Receive each packet, dump it out, and send it back
|
||||
//
|
||||
// This is untouched from the pingpair example.
|
||||
//
|
||||
|
||||
if ( role == role_pong_back )
|
||||
{
|
||||
// if there is data ready
|
||||
if ( radio.available() )
|
||||
{
|
||||
// Dump the payloads until we've gotten everything
|
||||
unsigned long got_time;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Fetch the payload, and see if this was the last one.
|
||||
done = radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it. Include our time, because the ping_out millis counter is unreliable
|
||||
// due to it sleeping
|
||||
printf("Got payload %lu @ %lu...",got_time,millis());
|
||||
}
|
||||
|
||||
// First, stop listening so we can talk
|
||||
radio.stopListening();
|
||||
|
||||
// Send the final one back.
|
||||
radio.write( &got_time, sizeof(unsigned long) );
|
||||
printf("Sent response.\n\r");
|
||||
|
||||
// Now, resume listening so we catch the next packets.
|
||||
radio.startListening();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Sleep helpers
|
||||
//
|
||||
|
||||
// 0=16ms, 1=32ms,2=64ms,3=125ms,4=250ms,5=500ms
|
||||
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
|
||||
|
||||
void setup_watchdog(uint8_t prescalar)
|
||||
{
|
||||
prescalar = min(9,prescalar);
|
||||
uint8_t wdtcsr = prescalar & 7;
|
||||
if ( prescalar & 8 )
|
||||
wdtcsr |= _BV(WDP3);
|
||||
|
||||
MCUSR &= ~_BV(WDRF);
|
||||
WDTCSR = _BV(WDCE) | _BV(WDE);
|
||||
WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE);
|
||||
}
|
||||
|
||||
ISR(WDT_vect)
|
||||
{
|
||||
--sleep_cycles_remaining;
|
||||
}
|
||||
|
||||
void do_sleep(void)
|
||||
{
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
|
||||
sleep_enable();
|
||||
|
||||
sleep_mode(); // System sleeps here
|
||||
|
||||
sleep_disable(); // System continues execution here when watchdog timed out
|
||||
}
|
||||
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
fdevopen( &serial_putc, 0 );
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
This program sends readings from four or more sensor readings and appends
|
||||
addr data pipes to the beginning of the payloads.
|
||||
|
||||
The receiver is a RPi accepting 6 pipes and display received payload to the screen
|
||||
|
||||
RPi receiver will return the receive payload for sender to calculate the rtt
|
||||
if the string compared matched
|
||||
|
||||
Max payload size is 32 bytes
|
||||
|
||||
Forked RF24 at github :-
|
||||
https://github.com/stanleyseow/RF24
|
||||
|
||||
Date : 5/03/2013
|
||||
|
||||
Written by Stanley Seow
|
||||
stanleyseow@gmai.com
|
||||
*/
|
||||
|
||||
#include <LiquidCrystal.h>
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
#define RF_SETUP 0x17
|
||||
|
||||
LiquidCrystal lcd(10, 7, 3, 4, 5, 6);
|
||||
// Make way for the SPI pins
|
||||
// 10 -> LCD 4
|
||||
// 7 -> LCD 6
|
||||
// 3 -> LCD 11
|
||||
// 4 -> LCD 12
|
||||
// 5 -> LCD 13
|
||||
// 6 -> LCD 14
|
||||
|
||||
// Set up nRF24L01 radio on SPI pin for CE, CSN
|
||||
RF24 radio(8,9);
|
||||
|
||||
// Radio pipe addresses for the 2 nodes to communicate.
|
||||
// const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
|
||||
// const uint64_t pipes[2] = { 0xF0F0F0F0E2LL, 0xF0F0F0F0D2LL };
|
||||
// const uint64_t pipes[2] = { 0xF0F0F0F0E3LL, 0xF0F0F0F0D2LL };
|
||||
const uint64_t pipes[2] = { 0xF0F0F0F0F1LL, 0xF0F0F0F0D2LL };
|
||||
// const uint64_t pipes[2] = { 0xF0F0F0F0F2LL, 0xF0F0F0F0D2LL };
|
||||
// Pipe0 is F0F0F0F0D2 ( same as reading pipe )
|
||||
|
||||
char receivePayload[32];
|
||||
int counter=0;
|
||||
int timeoutTimer = 500;
|
||||
int loops = 0;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
|
||||
// Setup LCD
|
||||
lcd.begin(16,2);
|
||||
lcd.clear();
|
||||
lcd.setCursor(0,0);
|
||||
lcd.print("Ard Remote Node 2");
|
||||
|
||||
Serial.begin(57600);
|
||||
|
||||
printf_begin();
|
||||
printf("Sending nodeID & 4 sensor data\n\r");
|
||||
|
||||
radio.begin();
|
||||
|
||||
// Enable this seems to work better
|
||||
radio.enableDynamicPayloads();
|
||||
radio.setAutoAck(1);
|
||||
|
||||
// Setup default radio settings
|
||||
|
||||
radio.setDataRate(RF24_1MBPS);
|
||||
radio.setPALevel(RF24_PA_MAX);
|
||||
radio.setChannel(76);
|
||||
radio.setCRCLength(RF24_CRC_16);
|
||||
radio.setRetries(15,15);
|
||||
|
||||
radio.openWritingPipe(pipes[0]);
|
||||
radio.openReadingPipe(1,pipes[1]);
|
||||
|
||||
// Send only, ignore listening mode
|
||||
//radio.startListening();
|
||||
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
radio.printDetails();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
int Data1,Data2,Data3,Data4 = 0;
|
||||
char temp[5];
|
||||
char nodeID[12];
|
||||
bool timeout=0;
|
||||
int timeout_timer = 500;
|
||||
|
||||
// Use the last 2 pipes address as nodeID
|
||||
sprintf(nodeID,"%X",pipes[0]);
|
||||
|
||||
char outBuffer[31]=""; // Clear the outBuffer before every loop
|
||||
unsigned long send_time, rtt = 0;
|
||||
|
||||
// Get readings from sensors
|
||||
Data1 = counter++;
|
||||
Data2 = analogRead(0);
|
||||
Data3 = analogRead(1);
|
||||
Data4 = random(0,1000);
|
||||
|
||||
if ( counter > 999 ) counter = 0;
|
||||
|
||||
// Append nodeID to the beginning of the payload
|
||||
strcat(outBuffer,nodeID);
|
||||
strcat(outBuffer,",");
|
||||
|
||||
// Convert int to strings and append with zeros if number smaller than 3 digits
|
||||
// 000 to 999
|
||||
|
||||
sprintf(temp,"%03d",Data1);
|
||||
strcat(outBuffer,temp);
|
||||
|
||||
strcat(outBuffer,",");
|
||||
|
||||
sprintf(temp,"%04d",Data2);
|
||||
strcat(outBuffer,temp);
|
||||
|
||||
strcat(outBuffer,",");
|
||||
|
||||
sprintf(temp,"%04d",Data3);
|
||||
strcat(outBuffer,temp);
|
||||
|
||||
strcat(outBuffer,",");
|
||||
|
||||
sprintf(temp,"%03d",Data4);
|
||||
strcat(outBuffer,temp);
|
||||
|
||||
// End string with 0
|
||||
// strcat(outBuffer,0);
|
||||
|
||||
printf("outBuffer: %s len: %d\n\r",outBuffer, strlen(outBuffer));
|
||||
|
||||
//lcd.clear();
|
||||
//lcd.setCursor(0,0);
|
||||
|
||||
lcd.setCursor(2,0);
|
||||
lcd.print(outBuffer);
|
||||
|
||||
send_time = millis();
|
||||
|
||||
// Stop listening and write to radio
|
||||
radio.stopListening();
|
||||
|
||||
// Send to hub
|
||||
if ( radio.write( outBuffer, strlen(outBuffer)) ) {
|
||||
printf("Send successful\n\r");
|
||||
lcd.setCursor(0,0);
|
||||
lcd.print("1:");
|
||||
}
|
||||
else {
|
||||
printf("Send failed\n\r");
|
||||
lcd.setCursor(0,0);
|
||||
lcd.print("0:");
|
||||
}
|
||||
|
||||
radio.startListening();
|
||||
delay(20);
|
||||
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("R: ");
|
||||
|
||||
while ( radio.available() && !timeout ) {
|
||||
|
||||
uint8_t len = radio.getDynamicPayloadSize();
|
||||
radio.read( receivePayload, len);
|
||||
// receive_payload[len] = 0;
|
||||
Serial.print("inBuffer: ");
|
||||
Serial.println(receivePayload);
|
||||
|
||||
lcd.setCursor(2,1);
|
||||
lcd.print(receivePayload);
|
||||
|
||||
// Compare receive payload with outBuffer
|
||||
if ( ! strcmp(outBuffer, receivePayload) ) {
|
||||
rtt = millis() - send_time;
|
||||
|
||||
// Send beep to Pin 2
|
||||
digitalWrite(2,HIGH);
|
||||
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print("R: ");
|
||||
|
||||
lcd.setCursor(2,1);
|
||||
lcd.print(rtt);
|
||||
Serial.println(rtt);
|
||||
}
|
||||
|
||||
// Check for timeout and exit the while loop
|
||||
if ( millis() - send_time > timeout_timer ) {
|
||||
lcd.setCursor(2,1);
|
||||
lcd.print("Timeout");
|
||||
Serial.println("Timeout!!!");
|
||||
timeout = 1;
|
||||
loops = 0;
|
||||
}
|
||||
Serial.print(loops++);
|
||||
delay(10);
|
||||
} // End while
|
||||
|
||||
|
||||
Serial.flush();
|
||||
delay(250);
|
||||
digitalWrite(2,LOW);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
210
digistump-sam/libraries/RF24/examples/scanner/Jamfile
Normal file
210
digistump-sam/libraries/RF24/examples/scanner/Jamfile
Normal file
@@ -0,0 +1,210 @@
|
||||
# (1) Project Information
|
||||
|
||||
PROJECT_LIBS = SPI RF24 ;
|
||||
|
||||
# (2) Board Information
|
||||
|
||||
UPLOAD_PROTOCOL ?= stk500v1 ;
|
||||
UPLOAD_SPEED ?= 57600 ;
|
||||
MCU ?= atmega328p ;
|
||||
F_CPU ?= 16000000 ;
|
||||
CORE ?= arduino ;
|
||||
VARIANT ?= standard ;
|
||||
ARDUINO_VERSION ?= 100 ;
|
||||
|
||||
# (3) USB Ports
|
||||
|
||||
PORTS = p4 p6 p9 u0 u1 u2 ;
|
||||
PORT_p6 = /dev/tty.usbserial-A600eHIs ;
|
||||
PORT_p4 = /dev/tty.usbserial-A40081RP ;
|
||||
PORT_p9 = /dev/tty.usbserial-A9007LmI ;
|
||||
PORT_u0 = /dev/ttyUSB0 ;
|
||||
PORT_u1 = /dev/ttyUSB1 ;
|
||||
PORT_u2 = /dev/ttyUSB2 ;
|
||||
|
||||
# (4) Location of AVR tools
|
||||
#
|
||||
# This configuration assumes using avr-tools that were obtained separate from the Arduino
|
||||
# distribution.
|
||||
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
AVR_BIN = /usr/local/avrtools/bin ;
|
||||
AVR_ETC = /usr/local/avrtools/etc ;
|
||||
AVR_INCLUDE = /usr/local/avrtools/include ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR_BIN = /usr/bin ;
|
||||
AVR_INCLUDE = /usr/lib/avr/include ;
|
||||
AVR_ETC = /etc ;
|
||||
}
|
||||
|
||||
# (5) Directories where Arduino core and libraries are located
|
||||
|
||||
ARDUINO_DIR ?= /opt/Arduino ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/$(CORE) $(ARDUINO_DIR)/hardware/arduino/variants/$(VARIANT) ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
|
||||
#
|
||||
# --------------------------------------------------
|
||||
# Below this line usually never needs to be modified
|
||||
#
|
||||
|
||||
# Tool locations
|
||||
|
||||
CC = $(AVR_BIN)/avr-gcc ;
|
||||
C++ = $(AVR_BIN)/avr-g++ ;
|
||||
LINK = $(AVR_BIN)/avr-gcc ;
|
||||
OBJCOPY = $(AVR_BIN)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_BIN)/avrdude ;
|
||||
|
||||
# Flags
|
||||
|
||||
DEFINES += F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
OPTIM = -Os ;
|
||||
CCFLAGS = -Wall -Wextra -mmcu=$(MCU) -ffunction-sections -fdata-sections ;
|
||||
C++FLAGS = $(CCFLAGS) -fno-exceptions -fno-strict-aliasing ;
|
||||
LINKFLAGS = $(OPTIM) -lm -Wl,--gc-sections -mmcu=$(MCU) ;
|
||||
AVRDUDEFLAGS = -V -F -D -C $(AVR_ETC)/avrdude.conf -p $(MCU) -c $(UPLOAD_PROTOCOL) -b $(UPLOAD_SPEED) ;
|
||||
|
||||
# Search everywhere for headers
|
||||
|
||||
HDRS = $(PWD) $(AVR_INCLUDE) $(ARDUINO_CORE) $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) ;
|
||||
|
||||
# Output locations
|
||||
|
||||
LOCATE_TARGET = $(F_CPU) ;
|
||||
LOCATE_SOURCE = $(F_CPU) ;
|
||||
|
||||
#
|
||||
# Custom rules
|
||||
#
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_SOURCE) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
if ( $(ARDUINO_VERSION) < 100 )
|
||||
{
|
||||
ARDUINO_H = WProgram.h ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ARDUINO_H = Arduino.h ;
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <$(ARDUINO_H)>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule C++Pde
|
||||
{
|
||||
local _CPP = $(>:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
C++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule UserObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .ino : C++Pde $(<) : $(>) ;
|
||||
case .pde : C++Pde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Objects
|
||||
{
|
||||
local _i ;
|
||||
|
||||
for _i in [ FGristFiles $(<) ]
|
||||
{
|
||||
local _b = $(_i:B)$(SUFOBJ) ;
|
||||
local _o = $(_b:G=$(SOURCE_GRIST:E)) ;
|
||||
Object $(_o) : $(_i) ;
|
||||
Depends obj : $(_o) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule Main
|
||||
{
|
||||
MainFromObjects $(<) : $(>:B)$(SUFOBJ) ;
|
||||
Objects $(>) ;
|
||||
}
|
||||
|
||||
rule Hex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
MakeLocate $(<) : $(LOCATE_TARGET) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions Hex
|
||||
{
|
||||
$(OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule Upload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
UploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions UploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDEFLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
#
|
||||
# Targets
|
||||
#
|
||||
|
||||
# Grab everything from the core directory
|
||||
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(ARDUINO_LIB)/$(PROJECT_LIBS)/utility $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp *.c ] ;
|
||||
|
||||
# Grab everything from the current dir
|
||||
PROJECT_MODULES += [ GLOB $(PWD) : *.c *.cpp *.pde *.ino ] ;
|
||||
|
||||
# Main output executable
|
||||
MAIN = $(PWD:B).elf ;
|
||||
|
||||
Main $(MAIN) : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
|
||||
Hex $(MAIN:B).hex : $(MAIN) ;
|
||||
|
||||
# Upload targets
|
||||
for _p in $(PORTS)
|
||||
{
|
||||
Upload $(_p) : $(PORT_$(_p)) : $(MAIN:B).hex ;
|
||||
}
|
||||
39
digistump-sam/libraries/RF24/examples/scanner/printf.h
Normal file
39
digistump-sam/libraries/RF24/examples/scanner/printf.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
124
digistump-sam/libraries/RF24/examples/scanner/scanner.pde
Normal file
124
digistump-sam/libraries/RF24/examples/scanner/scanner.pde
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Channel scanner
|
||||
*
|
||||
* Example to detect interference on the various channels available.
|
||||
* This is a good diagnostic tool to check whether you're picking a
|
||||
* good channel for your application.
|
||||
*
|
||||
* Inspired by cpixip.
|
||||
* See http://arduino.cc/forum/index.php/topic,54795.0.html
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
//
|
||||
// Channel info
|
||||
//
|
||||
|
||||
const uint8_t num_channels = 128;
|
||||
uint8_t values[num_channels];
|
||||
|
||||
//
|
||||
// Setup
|
||||
//
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/scanner/\n\r");
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
radio.setAutoAck(false);
|
||||
|
||||
// Get into standby mode
|
||||
radio.startListening();
|
||||
radio.stopListening();
|
||||
|
||||
// Print out header, high then low digit
|
||||
int i = 0;
|
||||
while ( i < num_channels )
|
||||
{
|
||||
printf("%x",i>>4);
|
||||
++i;
|
||||
}
|
||||
printf("\n\r");
|
||||
i = 0;
|
||||
while ( i < num_channels )
|
||||
{
|
||||
printf("%x",i&0xf);
|
||||
++i;
|
||||
}
|
||||
printf("\n\r");
|
||||
}
|
||||
|
||||
//
|
||||
// Loop
|
||||
//
|
||||
|
||||
const int num_reps = 100;
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
// Clear measurement values
|
||||
memset(values,0,sizeof(values));
|
||||
|
||||
// Scan all channels num_reps times
|
||||
int rep_counter = num_reps;
|
||||
while (rep_counter--)
|
||||
{
|
||||
int i = num_channels;
|
||||
while (i--)
|
||||
{
|
||||
// Select this channel
|
||||
radio.setChannel(i);
|
||||
|
||||
// Listen for a little
|
||||
radio.startListening();
|
||||
delayMicroseconds(128);
|
||||
radio.stopListening();
|
||||
|
||||
// Did we get a carrier?
|
||||
if ( radio.testCarrier() )
|
||||
++values[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Print out channel measurements, clamped to a single hex digit
|
||||
int i = 0;
|
||||
while ( i < num_channels )
|
||||
{
|
||||
printf("%x",min(0xf,values[i]&0xf));
|
||||
++i;
|
||||
}
|
||||
printf("\n\r");
|
||||
}
|
||||
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
206
digistump-sam/libraries/RF24/examples/starping/Jamfile
Normal file
206
digistump-sam/libraries/RF24/examples/starping/Jamfile
Normal file
@@ -0,0 +1,206 @@
|
||||
PROJECT_NAME = $(PWD:B) ;
|
||||
PROJECT_DIR = . ;
|
||||
PROJECT_LIBS = EEPROM SPI RF24 ;
|
||||
|
||||
OUT_DIR = ojam ;
|
||||
F_CPU = 16000000 ;
|
||||
MCU = atmega328p ;
|
||||
PORTS = /dev/tty.usbserial-A600eHIs /dev/tty.usbserial-A40081RP /dev/tty.usbserial-A9007LmI ;
|
||||
|
||||
UPLOAD_RATE = 57600 ;
|
||||
AVRDUDE_PROTOCOL = stk500v1 ;
|
||||
COM = 33 ;
|
||||
|
||||
# Host-specific overrides for locations
|
||||
if $(OS) = MACOSX
|
||||
{
|
||||
ARDUINO_VERSION = 22 ;
|
||||
OLD_DIR = /opt/arduino-0021 ;
|
||||
AVR_TOOLS_PATH = $(OLD_DIR)/hardware/tools/avr/bin ;
|
||||
AVRDUDECONFIG_PATH = $(OLD_DIR)/hardware/tools/avr/etc ;
|
||||
ARDUINO_DIR = /opt/Arduino ;
|
||||
ARDUINO_AVR = /usr/lib/avr/include ;
|
||||
}
|
||||
|
||||
# Where is everything?
|
||||
ARDUINO_VERSION ?= 22 ;
|
||||
AVR_TOOLS_PATH ?= /usr/bin ;
|
||||
ARDUINO_DIR ?= /opt/arduino-00$(ARDUINO_VERSION) ;
|
||||
ARDUINO_AVR ?= $(ARDUINO_DIR)/hardware/tools/avr/avr/include/avr ;
|
||||
AVRDUDECONFIG_PATH ?= $(ARDUINO_DIR)/hardware/tools ;
|
||||
ARDUINO_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino ;
|
||||
ARDUINO_LIB = $(ARDUINO_DIR)/libraries ;
|
||||
SKETCH_LIB = $(HOME)/Source/Arduino/libraries ;
|
||||
AVR_CC = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_CXX = $(AVR_TOOLS_PATH)/avr-g++ ;
|
||||
AVR_LD = $(AVR_TOOLS_PATH)/avr-gcc ;
|
||||
AVR_OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy ;
|
||||
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude ;
|
||||
|
||||
DEFINES = F_CPU=$(F_CPU)L ARDUINO=$(ARDUINO_VERSION) VERSION_H ;
|
||||
CTUNING = -ffunction-sections -fdata-sections ;
|
||||
CXXTUNING = -fno-exceptions -fno-strict-aliasing ;
|
||||
CFLAGS = -Os -Wall -Wextra -mmcu=$(MCU) $(CTUNING) ;
|
||||
CXXFLAGS = $(CFLAGS) $(CXXTUNING) ;
|
||||
LDFLAGS = -Os -lm -Wl,--gc-sections -mmcu=atmega328p ;
|
||||
|
||||
# Search everywhere for headers
|
||||
HDRS = $(PROJECT_DIR) $(ARDUINO_AVR) $(ARDUINO_CORE) [ GLOB $(ARDUINO_LIB) $(SKETCH_LIB) : [^.]* ] ;
|
||||
|
||||
# Grab everything from the core directory
|
||||
CORE_MODULES = [ GLOB $(ARDUINO_CORE) : *.c *.cpp ] ;
|
||||
|
||||
# Grab everything from libraries. To avoid this "grab everything" behaviour, you
|
||||
# can specify specific modules to pick up in PROJECT_MODULES
|
||||
LIB_MODULES = [ GLOB $(ARDUINO_LIB)/$(PROJECT_LIBS) $(SKETCH_LIB)/$(PROJECT_LIBS) : *.cpp ] ;
|
||||
|
||||
# In addition to explicitly-specified program modules, pick up anything from the current
|
||||
# dir.
|
||||
PROJECT_MODULES += [ GLOB $(PROJECT_DIR) : *.c *.cpp *.pde ] ;
|
||||
|
||||
# Shortcut for the out files
|
||||
OUT = $(OUT_DIR)/$(PROJECT_NAME) ;
|
||||
|
||||
# AvrDude setup
|
||||
AVRDUDE_FLAGS = -V -F -D -C $(AVRDUDECONFIG_PATH)/avrdude.conf -p $(MCU) -c $(AVRDUDE_PROTOCOL) -b $(UPLOAD_RATE) ;
|
||||
|
||||
rule GitVersion
|
||||
{
|
||||
Always $(<) ;
|
||||
Depends all : $(<) ;
|
||||
}
|
||||
|
||||
actions GitVersion
|
||||
{
|
||||
echo "const char program_version[] = \"\\" > $(<)
|
||||
git log -1 --pretty=format:%h >> $(<)
|
||||
echo "\";" >> $(<)
|
||||
}
|
||||
|
||||
GitVersion version.h ;
|
||||
|
||||
rule AvrCc
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrCc
|
||||
{
|
||||
$(AVR_CC) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule AvrC++
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
|
||||
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
|
||||
}
|
||||
|
||||
actions AvrC++
|
||||
{
|
||||
$(AVR_CXX) -c -o $(<) $(CCHDRS) $(CCDEFS) $(CXXFLAGS) $(>)
|
||||
}
|
||||
|
||||
rule Pde
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Clean clean : $(<) ;
|
||||
|
||||
}
|
||||
|
||||
actions Pde
|
||||
{
|
||||
echo "#include <WProgram.h>" > $(<)
|
||||
echo "#line 1 \"$(>)\"" >> $(<)
|
||||
cat $(>) >> $(<)
|
||||
}
|
||||
|
||||
rule AvrPde
|
||||
{
|
||||
local _CPP = $(OUT_DIR)/$(_I:B).cpp ;
|
||||
Pde $(_CPP) : $(>) ;
|
||||
AvrC++ $(<) : $(_CPP) ;
|
||||
}
|
||||
|
||||
rule AvrObject
|
||||
{
|
||||
switch $(>:S)
|
||||
{
|
||||
case .c : AvrCc $(<) : $(>) ;
|
||||
case .cpp : AvrC++ $(<) : $(>) ;
|
||||
case .pde : AvrPde $(<) : $(>) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrObjects
|
||||
{
|
||||
for _I in $(<)
|
||||
{
|
||||
AvrObject $(OUT_DIR)/$(_I:B).o : $(_I) ;
|
||||
}
|
||||
}
|
||||
|
||||
rule AvrMainFromObjects
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
MkDir $(<:D) ;
|
||||
Depends all : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrMainFromObjects
|
||||
{
|
||||
$(AVR_LD) $(LDFLAGS) -o $(<) $(>)
|
||||
}
|
||||
|
||||
rule AvrMain
|
||||
{
|
||||
AvrMainFromObjects $(<) : $(OUT_DIR)/$(>:B).o ;
|
||||
AvrObjects $(>) ;
|
||||
}
|
||||
|
||||
rule AvrHex
|
||||
{
|
||||
Depends $(<) : $(>) ;
|
||||
Depends $(<) : $(<:D) ;
|
||||
Depends hex : $(<) ;
|
||||
Clean clean : $(<) ;
|
||||
}
|
||||
|
||||
actions AvrHex
|
||||
{
|
||||
$(AVR_OBJCOPY) -O ihex -R .eeprom $(>) $(<)
|
||||
}
|
||||
|
||||
rule AvrUpload
|
||||
{
|
||||
Depends $(1) : $(2) ;
|
||||
Depends $(2) : $(3) ;
|
||||
NotFile $(1) ;
|
||||
Always $(1) ;
|
||||
Always $(2) ;
|
||||
AvrUploadAction $(2) : $(3) ;
|
||||
}
|
||||
|
||||
actions AvrUploadAction
|
||||
{
|
||||
$(AVRDUDE) $(AVRDUDE_FLAGS) -P $(<) $(AVRDUDE_WRITE_FLASH) -U flash:w:$(>):i
|
||||
}
|
||||
|
||||
AvrMain $(OUT).elf : $(CORE_MODULES) $(LIB_MODULES) $(PROJECT_MODULES) ;
|
||||
AvrHex $(OUT).hex : $(OUT).elf ;
|
||||
|
||||
AvrUpload p6 : /dev/tty.usbserial-A600eHIs : $(OUT).hex ;
|
||||
AvrUpload p4 : /dev/tty.usbserial-A40081RP : $(OUT).hex ;
|
||||
AvrUpload p9 : /dev/tty.usbserial-A9007LmI : $(OUT).hex ;
|
||||
|
||||
39
digistump-sam/libraries/RF24/examples/starping/printf.h
Normal file
39
digistump-sam/libraries/RF24/examples/starping/printf.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file printf.h
|
||||
*
|
||||
* Setup necessary to direct stdout to the Arduino Serial library, which
|
||||
* enables 'printf'
|
||||
*/
|
||||
|
||||
#ifndef __PRINTF_H__
|
||||
#define __PRINTF_H__
|
||||
|
||||
#ifdef ARDUINO
|
||||
|
||||
int serial_putc( char c, FILE * )
|
||||
{
|
||||
Serial.write( c );
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void printf_begin(void)
|
||||
{
|
||||
#if !defined(__arm__)
|
||||
fdevopen( &serial_putc, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
#error This example is only for use on Arduino.
|
||||
#endif // ARDUINO
|
||||
|
||||
#endif // __PRINTF_H__
|
||||
293
digistump-sam/libraries/RF24/examples/starping/starping.pde
Normal file
293
digistump-sam/libraries/RF24/examples/starping/starping.pde
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example RF Radio Ping Star Group
|
||||
*
|
||||
* This sketch is a more complex example of using the RF24 library for Arduino.
|
||||
* Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the
|
||||
* role_pin low, and the others will be 'ping transmit' units. The ping units
|
||||
* unit will send out the value of millis() once a second. The pong unit will
|
||||
* respond back with a copy of the value. Each ping unit can get that response
|
||||
* back, and determine how long the whole cycle took.
|
||||
*
|
||||
* This example requires a bit more complexity to determine which unit is which.
|
||||
* The pong receiver is identified by having its role_pin tied to ground.
|
||||
* The ping senders are further differentiated by a byte in eeprom.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <EEPROM.h>
|
||||
#include "nRF24L01.h"
|
||||
#include "RF24.h"
|
||||
#include "printf.h"
|
||||
|
||||
//
|
||||
// Hardware configuration
|
||||
//
|
||||
|
||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||
|
||||
RF24 radio(53,52);
|
||||
|
||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||
// Leave open to be the 'pong' receiver.
|
||||
const int role_pin = 7;
|
||||
|
||||
//
|
||||
// Topology
|
||||
//
|
||||
|
||||
// Radio pipe addresses for the nodes to communicate. Only ping nodes need
|
||||
// dedicated pipes in this topology. Each ping node has a talking pipe
|
||||
// that it will ping into, and a listening pipe that it will listen for
|
||||
// the pong. The pong node listens on all the ping node talking pipes
|
||||
// and sends the pong back on the sending node's specific listening pipe.
|
||||
|
||||
const uint64_t talking_pipes[5] = { 0xF0F0F0F0D2LL, 0xF0F0F0F0C3LL, 0xF0F0F0F0B4LL, 0xF0F0F0F0A5LL, 0xF0F0F0F096LL };
|
||||
const uint64_t listening_pipes[5] = { 0x3A3A3A3AD2LL, 0x3A3A3A3AC3LL, 0x3A3A3A3AB4LL, 0x3A3A3A3AA5LL, 0x3A3A3A3A96LL };
|
||||
|
||||
//
|
||||
// Role management
|
||||
//
|
||||
// Set up role. This sketch uses the same software for all the nodes
|
||||
// in this system. Doing so greatly simplifies testing. The hardware itself specifies
|
||||
// which node it is.
|
||||
//
|
||||
// This is done through the role_pin
|
||||
//
|
||||
|
||||
// The various roles supported by this sketch
|
||||
typedef enum { role_invalid = 0, role_ping_out, role_pong_back } role_e;
|
||||
|
||||
// The debug-friendly names of those roles
|
||||
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
|
||||
|
||||
// The role of the current running sketch
|
||||
role_e role;
|
||||
|
||||
//
|
||||
// Address management
|
||||
//
|
||||
|
||||
// Where in EEPROM is the address stored?
|
||||
const uint8_t address_at_eeprom_location = 0;
|
||||
|
||||
// What is our address (SRAM cache of the address from EEPROM)
|
||||
// Note that zero is an INVALID address. The pong back unit takes address
|
||||
// 1, and the rest are 2-6
|
||||
uint8_t node_address;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
//
|
||||
// Role
|
||||
//
|
||||
|
||||
// set up the role pin
|
||||
pinMode(role_pin, INPUT);
|
||||
digitalWrite(role_pin,HIGH);
|
||||
delay(20); // Just to get a solid reading on the role pin
|
||||
|
||||
// read the address pin, establish our role
|
||||
if ( digitalRead(role_pin) )
|
||||
role = role_ping_out;
|
||||
else
|
||||
role = role_pong_back;
|
||||
|
||||
//
|
||||
// Address
|
||||
//
|
||||
|
||||
if ( role == role_pong_back )
|
||||
node_address = 1;
|
||||
else
|
||||
{
|
||||
// Read the address from EEPROM
|
||||
uint8_t reading = EEPROM.read(address_at_eeprom_location);
|
||||
|
||||
// If it is in a valid range for node addresses, it is our
|
||||
// address.
|
||||
if ( reading >= 2 && reading <= 6 )
|
||||
node_address = reading;
|
||||
|
||||
// Otherwise, it is invalid, so set our address AND ROLE to 'invalid'
|
||||
else
|
||||
{
|
||||
node_address = 0;
|
||||
role = role_invalid;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Print preamble
|
||||
//
|
||||
|
||||
Serial.begin(57600);
|
||||
printf_begin();
|
||||
printf("\n\rRF24/examples/starping/\n\r");
|
||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||
printf("ADDRESS: %i\n\r",node_address);
|
||||
|
||||
//
|
||||
// Setup and configure rf radio
|
||||
//
|
||||
|
||||
radio.begin();
|
||||
|
||||
//
|
||||
// Open pipes to other nodes for communication
|
||||
//
|
||||
|
||||
// The pong node listens on all the ping node talking pipes
|
||||
// and sends the pong back on the sending node's specific listening pipe.
|
||||
if ( role == role_pong_back )
|
||||
{
|
||||
radio.openReadingPipe(1,talking_pipes[0]);
|
||||
radio.openReadingPipe(2,talking_pipes[1]);
|
||||
radio.openReadingPipe(3,talking_pipes[2]);
|
||||
radio.openReadingPipe(4,talking_pipes[3]);
|
||||
radio.openReadingPipe(5,talking_pipes[4]);
|
||||
}
|
||||
|
||||
// Each ping node has a talking pipe that it will ping into, and a listening
|
||||
// pipe that it will listen for the pong.
|
||||
if ( role == role_ping_out )
|
||||
{
|
||||
// Write on our talking pipe
|
||||
radio.openWritingPipe(talking_pipes[node_address-2]);
|
||||
// Listen on our listening pipe
|
||||
radio.openReadingPipe(1,listening_pipes[node_address-2]);
|
||||
}
|
||||
|
||||
//
|
||||
// Start listening
|
||||
//
|
||||
|
||||
radio.startListening();
|
||||
|
||||
//
|
||||
// Dump the configuration of the rf unit for debugging
|
||||
//
|
||||
|
||||
radio.printDetails();
|
||||
|
||||
//
|
||||
// Prompt the user to assign a node address if we don't have one
|
||||
//
|
||||
|
||||
if ( role == role_invalid )
|
||||
{
|
||||
printf("\n\r*** NO NODE ADDRESS ASSIGNED *** Send 1 through 6 to assign an address\n\r");
|
||||
}
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
//
|
||||
// Ping out role. Repeatedly send the current time
|
||||
//
|
||||
|
||||
if (role == role_ping_out)
|
||||
{
|
||||
// First, stop listening so we can talk.
|
||||
radio.stopListening();
|
||||
|
||||
// Take the time, and send it. This will block until complete
|
||||
unsigned long time = millis();
|
||||
printf("Now sending %lu...",time);
|
||||
radio.write( &time, sizeof(unsigned long) );
|
||||
|
||||
// Now, continue listening
|
||||
radio.startListening();
|
||||
|
||||
// Wait here until we get a response, or timeout (250ms)
|
||||
unsigned long started_waiting_at = millis();
|
||||
bool timeout = false;
|
||||
while ( ! radio.available() && ! timeout )
|
||||
if (millis() - started_waiting_at > 250 )
|
||||
timeout = true;
|
||||
|
||||
// Describe the results
|
||||
if ( timeout )
|
||||
{
|
||||
printf("Failed, response timed out.\n\r");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grab the response, compare, and send to debugging spew
|
||||
unsigned long got_time;
|
||||
radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
|
||||
}
|
||||
|
||||
// Try again 1s later
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
//
|
||||
// Pong back role. Receive each packet, dump it out, and send it back
|
||||
//
|
||||
|
||||
if ( role == role_pong_back )
|
||||
{
|
||||
// if there is data ready
|
||||
uint8_t pipe_num;
|
||||
if ( radio.available(&pipe_num) )
|
||||
{
|
||||
// Dump the payloads until we've gotten everything
|
||||
unsigned long got_time;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
// Fetch the payload, and see if this was the last one.
|
||||
done = radio.read( &got_time, sizeof(unsigned long) );
|
||||
|
||||
// Spew it
|
||||
printf("Got payload %lu from node %i...",got_time,pipe_num+1);
|
||||
}
|
||||
|
||||
// First, stop listening so we can talk
|
||||
radio.stopListening();
|
||||
|
||||
// Open the correct pipe for writing
|
||||
radio.openWritingPipe(listening_pipes[pipe_num-1]);
|
||||
|
||||
// Retain the low 2 bytes to identify the pipe for the spew
|
||||
uint16_t pipe_id = listening_pipes[pipe_num-1] & 0xffff;
|
||||
|
||||
// Send the final one back.
|
||||
radio.write( &got_time, sizeof(unsigned long) );
|
||||
printf("Sent response to %04x.\n\r",pipe_id);
|
||||
|
||||
// Now, resume listening so we catch the next packets.
|
||||
radio.startListening();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Listen for serial input, which is how we set the address
|
||||
//
|
||||
if (Serial.available())
|
||||
{
|
||||
// If the character on serial input is in a valid range...
|
||||
char c = Serial.read();
|
||||
if ( c >= '1' && c <= '6' )
|
||||
{
|
||||
// It is our address
|
||||
EEPROM.write(address_at_eeprom_location,c-'0');
|
||||
|
||||
// And we are done right now (no easy way to soft reset)
|
||||
printf("\n\rManually reset address to: %c\n\rPress RESET to continue!",c);
|
||||
while(1) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
// vim:ai:ci sts=2 sw=2 ft=cpp
|
||||
13
digistump-sam/libraries/RF24/keywords.txt
Normal file
13
digistump-sam/libraries/RF24/keywords.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
RF24 KEYWORD1
|
||||
begin KEYWORD2
|
||||
setChannel KEYWORD2
|
||||
setPayloadSize KEYWORD2
|
||||
getPayloadSize KEYWORD2
|
||||
print_details KEYWORD2
|
||||
startListening KEYWORD2
|
||||
stopListening KEYWORD2
|
||||
write KEYWORD2
|
||||
available KEYWORD2
|
||||
read KEYWORD2
|
||||
openWritingPipe KEYWORD2
|
||||
openReadingPipe KEYWORD2
|
||||
@@ -0,0 +1,55 @@
|
||||
#############################################################################
|
||||
#
|
||||
# Makefile for librf24-bcm on Raspberry Pi
|
||||
#
|
||||
# License: GPL (General Public License)
|
||||
# Author: Charles-Henri Hallard
|
||||
# Date: 2013/03/13
|
||||
#
|
||||
# Description:
|
||||
# ------------
|
||||
# use make all and mak install to install the library
|
||||
# You can change the install directory by editing the LIBDIR line
|
||||
#
|
||||
PREFIX=/usr/local
|
||||
|
||||
# Library parameters
|
||||
# where to put the lib
|
||||
LIBDIR=$(PREFIX)/lib
|
||||
# lib name
|
||||
LIB=librf24-bcm
|
||||
# shared library name
|
||||
LIBNAME=$(LIB).so.1.0
|
||||
|
||||
|
||||
# The recommended compiler flags for the Raspberry Pi
|
||||
CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s
|
||||
|
||||
# make all
|
||||
# reinstall the library after each recompilation
|
||||
all: librf24-bcm install
|
||||
|
||||
# Make the library
|
||||
librf24-bcm: RF24.o bcm2835.o
|
||||
g++ -shared -Wl,-soname,$@.so.1 ${CCFLAGS} -o ${LIBNAME} $^
|
||||
|
||||
# Library parts
|
||||
RF24.o: RF24.cpp
|
||||
g++ -Wall -fPIC ${CCFLAGS} -c $^
|
||||
|
||||
bcm2835.o: bcm2835.c
|
||||
gcc -Wall -fPIC ${CCFLAGS} -c $^
|
||||
|
||||
# clear build files
|
||||
clean:
|
||||
rm -rf *.o ${LIB}.*
|
||||
|
||||
# Install the library to LIBPATH
|
||||
install:
|
||||
@echo "[Install]"
|
||||
@if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi
|
||||
#@install -m 0755 ${LIB}.a ${LIBDIR}
|
||||
@install -m 0755 ${LIBNAME} ${LIBDIR}
|
||||
@ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so.1
|
||||
@ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so
|
||||
@ldconfig
|
||||
1088
digistump-sam/libraries/RF24/librf24-rpi/librf24-bcm/RF24.cpp
Normal file
1088
digistump-sam/libraries/RF24/librf24-rpi/librf24-bcm/RF24.cpp
Normal file
File diff suppressed because it is too large
Load Diff
804
digistump-sam/libraries/RF24/librf24-rpi/librf24-bcm/RF24.h
Normal file
804
digistump-sam/libraries/RF24/librf24-rpi/librf24-bcm/RF24.h
Normal file
@@ -0,0 +1,804 @@
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
|
||||
03/17/2013 : Charles-Henri Hallard (http://hallard.me)
|
||||
Modified to use with Arduipi board http://hallard.me/arduipi
|
||||
Modified to use the great bcm2835 library for I/O and SPI
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file RF24.h
|
||||
*
|
||||
* Class declaration for RF24 and helper enums
|
||||
*/
|
||||
|
||||
#ifndef __RF24_H__
|
||||
#define __RF24_H__
|
||||
|
||||
#include "RF24_config.h"
|
||||
#include "./bcm2835.h"
|
||||
|
||||
|
||||
/**
|
||||
* Power Amplifier level.
|
||||
*
|
||||
* For use with setPALevel()
|
||||
*/
|
||||
typedef enum { RF24_PA_MIN = 0,RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR } rf24_pa_dbm_e ;
|
||||
|
||||
/**
|
||||
* Data rate. How fast data moves through the air.
|
||||
*
|
||||
* For use with setDataRate()
|
||||
*/
|
||||
typedef enum { RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS } rf24_datarate_e;
|
||||
|
||||
/**
|
||||
* CRC Length. How big (if any) of a CRC is included.
|
||||
*
|
||||
* For use with setCRCLength()
|
||||
*/
|
||||
typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e;
|
||||
|
||||
/**
|
||||
* Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
|
||||
*/
|
||||
|
||||
class RF24
|
||||
{
|
||||
private:
|
||||
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
|
||||
uint8_t csn_pin; /**< SPI Chip select */
|
||||
uint16_t spi_speed; /**< SPI Bus Speed */
|
||||
bool wide_band; /* 2Mbs data rate in use? */
|
||||
bool p_variant; /* False for RF24L01 and true for RF24L01P */
|
||||
uint8_t payload_size; /**< Fixed size of payloads */
|
||||
bool ack_payload_available; /**< Whether there is an ack payload waiting */
|
||||
bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
|
||||
uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. */
|
||||
uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */
|
||||
//uint32_t spispeed;
|
||||
uint8_t debug ; /* Debug flag */
|
||||
uint8_t spi_rxbuff[32] ; //SPI receive buffer (payload max 32 bytes)
|
||||
uint8_t spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command)
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @name Low-level internal interface.
|
||||
*
|
||||
* Protected methods that address the chip directly. Regular users cannot
|
||||
* ever call these. They are documented for completeness and for developers who
|
||||
* may want to extend this class.
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
|
||||
/**
|
||||
* Read a chunk of data in from a register
|
||||
*
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param buf Where to put the data
|
||||
* @param len How many bytes of data to transfer
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Read single byte from a register
|
||||
*
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @return Current value of register @p reg
|
||||
*/
|
||||
uint8_t read_register(uint8_t reg);
|
||||
|
||||
/**
|
||||
* Write a chunk of data to a register
|
||||
*
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param buf Where to get the data
|
||||
* @param len How many bytes of data to transfer
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Write a single byte to a register
|
||||
*
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param value The new value to write
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t write_register(uint8_t reg, uint8_t value);
|
||||
|
||||
/**
|
||||
* Write the transmit payload
|
||||
*
|
||||
* The size of data written is the fixed payload size, see getPayloadSize()
|
||||
*
|
||||
* @param buf Where to get the data
|
||||
* @param len Number of bytes to be sent
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t write_payload(const void* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Read the receive payload
|
||||
*
|
||||
* The size of data read is the fixed payload size, see getPayloadSize()
|
||||
*
|
||||
* @param buf Where to put the data
|
||||
* @param len Maximum number of bytes to read
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t read_payload(void* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Empty the receive buffer
|
||||
*
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t flush_rx(void);
|
||||
|
||||
/**
|
||||
* Empty the transmit buffer
|
||||
*
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t flush_tx(void);
|
||||
|
||||
/**
|
||||
* Retrieve the current status of the chip
|
||||
*
|
||||
* @return Current value of status register
|
||||
*/
|
||||
uint8_t get_status(void);
|
||||
|
||||
/**
|
||||
* Decode and print the given status to stdout
|
||||
*
|
||||
* @param status Status value to print
|
||||
*
|
||||
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
|
||||
*/
|
||||
void print_status(uint8_t status);
|
||||
|
||||
/**
|
||||
* Decode and print the given 'observe_tx' value to stdout
|
||||
*
|
||||
* @param value The observe_tx value to print
|
||||
*
|
||||
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
|
||||
*/
|
||||
void print_observe_tx(uint8_t value);
|
||||
|
||||
/**
|
||||
* Print the name and value of an 8-bit register to stdout
|
||||
*
|
||||
* Optionally it can print some quantity of successive
|
||||
* registers on the same line. This is useful for printing a group
|
||||
* of related registers on one line.
|
||||
*
|
||||
* @param name Name of the register
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param qty How many successive registers to print
|
||||
*/
|
||||
void print_byte_register(const char* name, uint8_t reg, uint8_t qty = 1);
|
||||
|
||||
/**
|
||||
* Print the name and value of a 40-bit address register to stdout
|
||||
*
|
||||
* Optionally it can print some quantity of successive
|
||||
* registers on the same line. This is useful for printing a group
|
||||
* of related registers on one line.
|
||||
*
|
||||
* @param name Name of the register
|
||||
* @param reg Which register. Use constants from nRF24L01.h
|
||||
* @param qty How many successive registers to print
|
||||
*/
|
||||
void print_address_register(const char* name, uint8_t reg, uint8_t qty = 1);
|
||||
|
||||
/**
|
||||
* Turn on or off the special features of the chip
|
||||
*
|
||||
* The chip has certain 'features' which are only available when the 'features'
|
||||
* are enabled. See the datasheet for details.
|
||||
*/
|
||||
void toggle_features(void);
|
||||
/**@}*/
|
||||
|
||||
public:
|
||||
/**
|
||||
* @name Primary public interface
|
||||
*
|
||||
* These are the main methods you need to operate the chip
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Creates a new instance of this driver. Before using, you create an instance
|
||||
* and send in the unique pins that this chip is connected to.
|
||||
*
|
||||
* @param _cepin The pin attached to Chip Enable on the RF module
|
||||
* @param _cspin The pin attached to Chip Select
|
||||
*/
|
||||
RF24(uint8_t _cepin, uint8_t _cspin);
|
||||
RF24(uint8_t _cepin, uint8_t _cspin, uint32_t spispeed );
|
||||
|
||||
/**
|
||||
* Begin operation of the chip
|
||||
*
|
||||
* Call this in setup(), before calling any other methods.
|
||||
*/
|
||||
bool begin(void);
|
||||
|
||||
/**
|
||||
* Start listening on the pipes opened for reading.
|
||||
*
|
||||
* Be sure to call openReadingPipe() first. Do not call write() while
|
||||
* in this mode, without first calling stopListening(). Call
|
||||
* isAvailable() to check for incoming traffic, and read() to get it.
|
||||
*/
|
||||
void startListening(void);
|
||||
|
||||
/**
|
||||
* Stop listening for incoming messages
|
||||
*
|
||||
* Do this before calling write().
|
||||
*/
|
||||
void stopListening(void);
|
||||
|
||||
/**
|
||||
* Write to the open writing pipe
|
||||
*
|
||||
* Be sure to call openWritingPipe() first to set the destination
|
||||
* of where to write to.
|
||||
*
|
||||
* This blocks until the message is successfully acknowledged by
|
||||
* the receiver or the timeout/retransmit maxima are reached. In
|
||||
* the current configuration, the max delay here is 60ms.
|
||||
*
|
||||
* The maximum size of data written is the fixed payload size, see
|
||||
* getPayloadSize(). However, you can write less, and the remainder
|
||||
* will just be filled with zeroes.
|
||||
*
|
||||
* @param buf Pointer to the data to be sent
|
||||
* @param len Number of bytes to be sent
|
||||
* @return True if the payload was delivered successfully false if not
|
||||
*/
|
||||
bool write( const void* buf, uint8_t len );
|
||||
|
||||
/**
|
||||
* Test whether there are bytes available to be read
|
||||
*
|
||||
* @return True if there is a payload available, false if none is
|
||||
*/
|
||||
bool available(void);
|
||||
|
||||
/**
|
||||
* Read the payload
|
||||
*
|
||||
* Return the last payload received
|
||||
*
|
||||
* The size of data read is the fixed payload size, see getPayloadSize()
|
||||
*
|
||||
* @note I specifically chose 'void*' as a data type to make it easier
|
||||
* for beginners to use. No casting needed.
|
||||
*
|
||||
* @param buf Pointer to a buffer where the data should be written
|
||||
* @param len Maximum number of bytes to read into the buffer
|
||||
* @return True if the payload was delivered successfully false if not
|
||||
*/
|
||||
bool read( void* buf, uint8_t len );
|
||||
|
||||
/**
|
||||
* Open a pipe for writing
|
||||
*
|
||||
* Only one pipe can be open at once, but you can change the pipe
|
||||
* you'll listen to. Do not call this while actively listening.
|
||||
* Remember to stopListening() first.
|
||||
*
|
||||
* Addresses are 40-bit hex values, e.g.:
|
||||
*
|
||||
* @code
|
||||
* openWritingPipe(0xF0F0F0F0F0);
|
||||
* @endcode
|
||||
*
|
||||
* @param address The 40-bit address of the pipe to open. This can be
|
||||
* any value whatsoever, as long as you are the only one writing to it
|
||||
* and only one other radio is listening to it. Coordinate these pipe
|
||||
* addresses amongst nodes on the network.
|
||||
*/
|
||||
void openWritingPipe(uint64_t address);
|
||||
|
||||
/**
|
||||
* Open a pipe for reading
|
||||
*
|
||||
* Up to 6 pipes can be open for reading at once. Open all the
|
||||
* reading pipes, and then call startListening().
|
||||
*
|
||||
* @see openWritingPipe
|
||||
*
|
||||
* @warning Pipes 1-5 should share the first 32 bits.
|
||||
* Only the least significant byte should be unique, e.g.
|
||||
* @code
|
||||
* openReadingPipe(1,0xF0F0F0F0AA);
|
||||
* openReadingPipe(2,0xF0F0F0F066);
|
||||
* @endcode
|
||||
*
|
||||
* @warning Pipe 0 is also used by the writing pipe. So if you open
|
||||
* pipe 0 for reading, and then startListening(), it will overwrite the
|
||||
* writing pipe. Ergo, do an openWritingPipe() again before write().
|
||||
*
|
||||
* @todo Enforce the restriction that pipes 1-5 must share the top 32 bits
|
||||
*
|
||||
* @param number Which pipe# to open, 0-5.
|
||||
* @param address The 40-bit address of the pipe to open.
|
||||
*/
|
||||
void openReadingPipe(uint8_t number, uint64_t address);
|
||||
|
||||
/**@}*/
|
||||
/**
|
||||
* @name Optional Configurators
|
||||
*
|
||||
* Methods you can use to get or set the configuration of the chip.
|
||||
* None are required. Calling begin() sets up a reasonable set of
|
||||
* defaults.
|
||||
*/
|
||||
/**@{*/
|
||||
/**
|
||||
* Set the number and delay of retries upon failed submit
|
||||
*
|
||||
* @param delay How long to wait between each retry, in multiples of 250us,
|
||||
* max is 15. 0 means 250us, 15 means 4000us.
|
||||
* @param count How many retries before giving up, max 15
|
||||
*/
|
||||
void setRetries(uint8_t delay, uint8_t count);
|
||||
|
||||
/**
|
||||
* Set RF communication channel
|
||||
*
|
||||
* @param channel Which RF channel to communicate on, 0-127
|
||||
*/
|
||||
void setChannel(uint8_t channel);
|
||||
|
||||
/**
|
||||
* Set Static Payload Size
|
||||
*
|
||||
* This implementation uses a pre-stablished fixed payload size for all
|
||||
* transmissions. If this method is never called, the driver will always
|
||||
* transmit the maximum payload size (32 bytes), no matter how much
|
||||
* was sent to write().
|
||||
*
|
||||
* @todo Implement variable-sized payloads feature
|
||||
*
|
||||
* @param size The number of bytes in the payload
|
||||
*/
|
||||
void setPayloadSize(uint8_t size);
|
||||
|
||||
/**
|
||||
* Get Static Payload Size
|
||||
*
|
||||
* @see setPayloadSize()
|
||||
*
|
||||
* @return The number of bytes in the payload
|
||||
*/
|
||||
uint8_t getPayloadSize(void);
|
||||
|
||||
/**
|
||||
* Get Dynamic Payload Size
|
||||
*
|
||||
* For dynamic payloads, this pulls the size of the payload off
|
||||
* the chip
|
||||
*
|
||||
* @return Payload length of last-received dynamic payload
|
||||
*/
|
||||
uint8_t getDynamicPayloadSize(void);
|
||||
|
||||
/**
|
||||
* Enable custom payloads on the acknowledge packets
|
||||
*
|
||||
* Ack payloads are a handy way to return data back to senders without
|
||||
* manually changing the radio modes on both units.
|
||||
*
|
||||
* @see examples/pingpair_pl/pingpair_pl.pde
|
||||
*/
|
||||
void enableAckPayload(void);
|
||||
|
||||
/**
|
||||
* Enable dynamically-sized payloads
|
||||
*
|
||||
* This way you don't always have to send large packets just to send them
|
||||
* once in a while. This enables dynamic payloads on ALL pipes.
|
||||
*
|
||||
* @see examples/pingpair_pl/pingpair_dyn.pde
|
||||
*/
|
||||
void enableDynamicPayloads(void);
|
||||
|
||||
/**
|
||||
* Determine whether the hardware is an nRF24L01+ or not.
|
||||
*
|
||||
* @return true if the hardware is nRF24L01+ (or compatible) and false
|
||||
* if its not.
|
||||
*/
|
||||
bool isPVariant(void) ;
|
||||
|
||||
/**
|
||||
* Enable or disable auto-acknowlede packets
|
||||
*
|
||||
* This is enabled by default, so it's only needed if you want to turn
|
||||
* it off for some reason.
|
||||
*
|
||||
* @param enable Whether to enable (true) or disable (false) auto-acks
|
||||
*/
|
||||
void setAutoAck(bool enable);
|
||||
|
||||
/**
|
||||
* Enable or disable auto-acknowlede packets on a per pipeline basis.
|
||||
*
|
||||
* AA is enabled by default, so it's only needed if you want to turn
|
||||
* it off/on for some reason on a per pipeline basis.
|
||||
*
|
||||
* @param pipe Which pipeline to modify
|
||||
* @param enable Whether to enable (true) or disable (false) auto-acks
|
||||
*/
|
||||
void setAutoAck( uint8_t pipe, bool enable ) ;
|
||||
|
||||
/**
|
||||
* Set Power Amplifier (PA) level to one of four levels.
|
||||
* Relative mnemonics have been used to allow for future PA level
|
||||
* changes. According to 6.5 of the nRF24L01+ specification sheet,
|
||||
* they translate to: RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm,
|
||||
* RF24_PA_MED=-6dBM, and RF24_PA_HIGH=0dBm.
|
||||
*
|
||||
* @param level Desired PA level.
|
||||
*/
|
||||
void setPALevel( rf24_pa_dbm_e level ) ;
|
||||
|
||||
/**
|
||||
* Fetches the current PA level.
|
||||
*
|
||||
* @return Returns a value from the rf24_pa_dbm_e enum describing
|
||||
* the current PA setting. Please remember, all values represented
|
||||
* by the enum mnemonics are negative dBm. See setPALevel for
|
||||
* return value descriptions.
|
||||
*/
|
||||
rf24_pa_dbm_e getPALevel( void ) ;
|
||||
|
||||
/**
|
||||
* Set the transmission data rate
|
||||
*
|
||||
* @warning setting RF24_250KBPS will fail for non-plus units
|
||||
*
|
||||
* @param speed RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
|
||||
* @return true if the change was successful
|
||||
*/
|
||||
bool setDataRate(rf24_datarate_e speed);
|
||||
|
||||
/**
|
||||
* Fetches the transmission data rate
|
||||
*
|
||||
* @return Returns the hardware's currently configured datarate. The value
|
||||
* is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the
|
||||
* rf24_datarate_e enum.
|
||||
*/
|
||||
rf24_datarate_e getDataRate( void ) ;
|
||||
|
||||
/**
|
||||
* Set the CRC length
|
||||
*
|
||||
* @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
|
||||
*/
|
||||
void setCRCLength(rf24_crclength_e length);
|
||||
|
||||
/**
|
||||
* Get the CRC length
|
||||
*
|
||||
* @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
|
||||
*/
|
||||
rf24_crclength_e getCRCLength(void);
|
||||
|
||||
/**
|
||||
* Disable CRC validation
|
||||
*
|
||||
*/
|
||||
void disableCRC( void ) ;
|
||||
|
||||
/**@}*/
|
||||
/**
|
||||
* @name Advanced Operation
|
||||
*
|
||||
* Methods you can use to drive the chip in more advanced ways
|
||||
*/
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* Print a giant block of debugging information to stdout
|
||||
*
|
||||
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
|
||||
*/
|
||||
void printDetails(void);
|
||||
|
||||
/**
|
||||
* Enter low-power mode
|
||||
*
|
||||
* To return to normal power mode, either write() some data or
|
||||
* startListening, or powerUp().
|
||||
*/
|
||||
void powerDown(void);
|
||||
|
||||
/**
|
||||
* Leave low-power mode - making radio more responsive
|
||||
*
|
||||
* To return to low power mode, call powerDown().
|
||||
*/
|
||||
void powerUp(void) ;
|
||||
|
||||
/**
|
||||
* Test whether there are bytes available to be read
|
||||
*
|
||||
* Use this version to discover on which pipe the message
|
||||
* arrived.
|
||||
*
|
||||
* @param[out] pipe_num Which pipe has the payload available
|
||||
* @return True if there is a payload available, false if none is
|
||||
*/
|
||||
bool available(uint8_t* pipe_num);
|
||||
|
||||
/**
|
||||
* Non-blocking write to the open writing pipe
|
||||
*
|
||||
* Just like write(), but it returns immediately. To find out what happened
|
||||
* to the send, catch the IRQ and then call whatHappened().
|
||||
*
|
||||
* @see write()
|
||||
* @see whatHappened()
|
||||
*
|
||||
* @param buf Pointer to the data to be sent
|
||||
* @param len Number of bytes to be sent
|
||||
* @return True if the payload was delivered successfully false if not
|
||||
*/
|
||||
void startWrite( const void* buf, uint8_t len );
|
||||
|
||||
/**
|
||||
* Write an ack payload for the specified pipe
|
||||
*
|
||||
* The next time a message is received on @p pipe, the data in @p buf will
|
||||
* be sent back in the acknowledgement.
|
||||
*
|
||||
* @warning According to the data sheet, only three of these can be pending
|
||||
* at any time. I have not tested this.
|
||||
*
|
||||
* @param pipe Which pipe# (typically 1-5) will get this response.
|
||||
* @param buf Pointer to data that is sent
|
||||
* @param len Length of the data to send, up to 32 bytes max. Not affected
|
||||
* by the static payload set by setPayloadSize().
|
||||
*/
|
||||
void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len);
|
||||
|
||||
/**
|
||||
* Determine if an ack payload was received in the most recent call to
|
||||
* write().
|
||||
*
|
||||
* Call read() to retrieve the ack payload.
|
||||
*
|
||||
* @warning Calling this function clears the internal flag which indicates
|
||||
* a payload is available. If it returns true, you must read the packet
|
||||
* out as the very next interaction with the radio, or the results are
|
||||
* undefined.
|
||||
*
|
||||
* @return True if an ack payload is available.
|
||||
*/
|
||||
bool isAckPayloadAvailable(void);
|
||||
|
||||
/**
|
||||
* Call this when you get an interrupt to find out why
|
||||
*
|
||||
* Tells you what caused the interrupt, and clears the state of
|
||||
* interrupts.
|
||||
*
|
||||
* @param[out] tx_ok The send was successful (TX_DS)
|
||||
* @param[out] tx_fail The send failed, too many retries (MAX_RT)
|
||||
* @param[out] rx_ready There is a message waiting to be read (RX_DS)
|
||||
*/
|
||||
void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready);
|
||||
|
||||
/**
|
||||
* Test whether there was a carrier on the line for the
|
||||
* previous listening period.
|
||||
*
|
||||
* Useful to check for interference on the current channel.
|
||||
*
|
||||
* @return true if was carrier, false if not
|
||||
*/
|
||||
bool testCarrier(void);
|
||||
|
||||
/**
|
||||
* Test whether a signal (carrier or otherwise) greater than
|
||||
* or equal to -64dBm is present on the channel. Valid only
|
||||
* on nRF24L01P (+) hardware. On nRF24L01, use testCarrier().
|
||||
*
|
||||
* Useful to check for interference on the current channel and
|
||||
* channel hopping strategies.
|
||||
*
|
||||
* @return true if signal => -64dBm, false if not
|
||||
*/
|
||||
bool testRPD(void) ;
|
||||
|
||||
/**@}*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @example GettingStarted.pde
|
||||
*
|
||||
* This is an example which corresponds to my "Getting Started" blog post:
|
||||
* <a style="text-align:center" href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>.
|
||||
*
|
||||
* It is an example of how to use the RF24 class. Write this sketch to two
|
||||
* different nodes. Put one of the nodes into 'transmit' mode by connecting
|
||||
* with the serial monitor and sending a 'T'. The ping node sends the current
|
||||
* time to the pong node, which responds by sending the value back. The ping
|
||||
* node can then see how long the whole cycle took.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example nordic_fob.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class to receive signals from the
|
||||
* Sparkfun Nordic FOB. See http://www.sparkfun.com/products/8602 .
|
||||
* Thanks to Kirk Mower for providing test hardware.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example led_remote.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class to control a remote
|
||||
* bank of LED's using buttons on a remote control.
|
||||
*
|
||||
* Every time the buttons change on the remote, the entire state of
|
||||
* buttons is send to the led board, which displays the state.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class. Write this sketch to two
|
||||
* different nodes, connect the role_pin to ground on one. The ping node sends
|
||||
* the current time to the pong node, which responds by sending the value back.
|
||||
* The ping node can then see how long the whole cycle took.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair_maple.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class on the Maple. For a more
|
||||
* detailed explanation, see my blog post:
|
||||
* <a href="http://maniacbug.wordpress.com/2011/12/14/nrf24l01-running-on-maple-3/">nRF24L01+ Running on Maple</a>
|
||||
*
|
||||
* It will communicate well to an Arduino-based unit as well, so it's not for only Maple-to-Maple communication.
|
||||
*
|
||||
* Write this sketch to two different nodes,
|
||||
* connect the role_pin to ground on one. The ping node sends the current time to the pong node,
|
||||
* which responds by sending the value back. The ping node can then see how long the whole cycle
|
||||
* took.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example starping.pde
|
||||
*
|
||||
* This sketch is a more complex example of using the RF24 library for Arduino.
|
||||
* Deploy this on up to six nodes. Set one as the 'pong receiver' by tying the
|
||||
* role_pin low, and the others will be 'ping transmit' units. The ping units
|
||||
* unit will send out the value of millis() once a second. The pong unit will
|
||||
* respond back with a copy of the value. Each ping unit can get that response
|
||||
* back, and determine how long the whole cycle took.
|
||||
*
|
||||
* This example requires a bit more complexity to determine which unit is which.
|
||||
* The pong receiver is identified by having its role_pin tied to ground.
|
||||
* The ping senders are further differentiated by a byte in eeprom.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair_pl.pde
|
||||
*
|
||||
* This is an example of how to do two-way communication without changing
|
||||
* transmit/receive modes. Here, a payload is set to the transmitter within
|
||||
* the Ack packet of each transmission. Note that the payload is set BEFORE
|
||||
* the sender's message arrives.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair_irq.pde
|
||||
*
|
||||
* This is an example of how to user interrupts to interact with the radio.
|
||||
* It builds on the pingpair_pl example, and uses ack payloads.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example pingpair_sleepy.pde
|
||||
*
|
||||
* This is an example of how to use the RF24 class to create a battery-
|
||||
* efficient system. It is just like the pingpair.pde example, but the
|
||||
* ping node powers down the radio and sleeps the MCU after every
|
||||
* ping/pong cycle.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example scanner.pde
|
||||
*
|
||||
* Example to detect interference on the various channels available.
|
||||
* This is a good diagnostic tool to check whether you're picking a
|
||||
* good channel for your application.
|
||||
*
|
||||
* Inspired by cpixip.
|
||||
* See http://arduino.cc/forum/index.php/topic,54795.0.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* @mainpage Driver for nRF24L01(+) 2.4GHz Wireless Transceiver
|
||||
*
|
||||
* @section Goals Design Goals
|
||||
*
|
||||
* This library is designed to be...
|
||||
* @li Maximally compliant with the intended operation of the chip
|
||||
* @li Easy for beginners to use
|
||||
* @li Consumed with a public interface that's similiar to other Arduino standard libraries
|
||||
*
|
||||
* @section News News
|
||||
*
|
||||
* NOW COMPATIBLE WITH ARDUINO 1.0 - The 'master' branch and all examples work with both Arduino 1.0 and earlier versions.
|
||||
* Please <a href="https://github.com/maniacbug/RF24/issues/new">open an issue</a> if you find any problems using it with any version of Arduino.
|
||||
*
|
||||
* NOW COMPATIBLE WITH MAPLE - RF24 has been tested with the
|
||||
* <a href="http://leaflabs.com/store/#Maple-Native">Maple Native</a>,
|
||||
* and should work with any Maple board. See the pingpair_maple example.
|
||||
* Note that only the pingpair_maple example has been tested on Maple, although
|
||||
* the others can certainly be adapted.
|
||||
*
|
||||
* @section Useful Useful References
|
||||
*
|
||||
* Please refer to:
|
||||
*
|
||||
* @li <a href="http://maniacbug.github.com/RF24/">Documentation Main Page</a>
|
||||
* @li <a href="http://maniacbug.github.com/RF24/classRF24.html">RF24 Class Documentation</a>
|
||||
* @li <a href="https://github.com/maniacbug/RF24/">Source Code</a>
|
||||
* @li <a href="https://github.com/maniacbug/RF24/archives/master">Downloads Page</a>
|
||||
* @li <a href="http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf">Chip Datasheet</a>
|
||||
*
|
||||
* This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
|
||||
* the SPI hardware will go into 'slave' mode.
|
||||
*
|
||||
* @section More More Information
|
||||
*
|
||||
* @subpage FAQ
|
||||
*
|
||||
* @section Projects Projects
|
||||
*
|
||||
* Stuff I have built with RF24
|
||||
*
|
||||
* <img src="http://farm7.staticflickr.com/6044/6307669179_a8d19298a6_m.jpg" width="240" height="160" alt="RF24 Getting Started - Finished Product">
|
||||
*
|
||||
* <a style="text-align:center" href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>
|
||||
*
|
||||
* <img src="http://farm8.staticflickr.com/7159/6645514331_38eb2bdeaa_m.jpg" width="240" height="160" alt="Nordic FOB and nRF24L01+">
|
||||
*
|
||||
* <a style="text-align:center" href="http://maniacbug.wordpress.com/2012/01/08/nordic-fob/">Using the Sparkfun Nordic FOB</a>
|
||||
*
|
||||
* <img src="http://farm7.staticflickr.com/6097/6224308836_b9b3b421a3_m.jpg" width="240" height="160" alt="RF Duinode V3 (2V4)">
|
||||
*
|
||||
* <a href="http://maniacbug.wordpress.com/2011/10/19/sensor-node/">Low-Power Wireless Sensor Node</a>
|
||||
*
|
||||
* <img src="http://farm8.staticflickr.com/7012/6489477865_b56edb629b_m.jpg" width="240" height="161" alt="nRF24L01+ connected to Leaf Labs Maple Native">
|
||||
*
|
||||
* <a href="http://maniacbug.wordpress.com/2011/12/14/nrf24l01-running-on-maple-3/">nRF24L01+ Running on Maple</a>
|
||||
*/
|
||||
|
||||
#endif // __RF24_H__
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
/*
|
||||
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 2 as published by the Free Software Foundation.
|
||||
|
||||
03/17/2013 : Charles-Henri Hallard (http://hallard.me)
|
||||
Modified to use with Arduipi board http://hallard.me/arduipi
|
||||
Modified to use the great bcm2835 library for I/O and SPI
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __RF24_CONFIG_H__
|
||||
#define __RF24_CONFIG_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <stddef.h>
|
||||
#include "bcm2835.h"
|
||||
|
||||
// GCC a Arduino Missing
|
||||
#define max(a,b) (a>b?a:b)
|
||||
#define min(a,b) (a<b?a:b)
|
||||
#define _BV(x) (1<<(x))
|
||||
#define pgm_read_word(p) (*(p))
|
||||
#define pgm_read_byte(p) (*(p))
|
||||
|
||||
#endif // __RF24_CONFIG_H__
|
||||
// vim:ai:cin:sts=2 sw=2 ft=cpp
|
||||
1102
digistump-sam/libraries/RF24/librf24-rpi/librf24-bcm/bcm2835.c
Normal file
1102
digistump-sam/libraries/RF24/librf24-rpi/librf24-bcm/bcm2835.c
Normal file
File diff suppressed because it is too large
Load Diff
1169
digistump-sam/libraries/RF24/librf24-rpi/librf24-bcm/bcm2835.h
Normal file
1169
digistump-sam/libraries/RF24/librf24-rpi/librf24-bcm/bcm2835.h
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user