Skip to content

Commit e3b2495

Browse files
author
Nathan Seidle
committed
Add 2 I2C port example
1 parent 9cc720e commit e3b2495

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Making more I2C ports on the Artemis
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: June 21, 2019
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example shows how to add a 2nd (or 3rd) I2C bus to an Artemis carrier board.
10+
11+
The key to success is that when the SPIClass or TwoWire objects above are constructed they don't actually
12+
change any of the Special Function Registers (SFRs) in the Apollo3. That all happens when you use the .begin()
13+
method. This way it is acceptable to define as many different TwoWire or SPIClass objects as you want at one
14+
time using only one IOMaster instance. However it is *not* well-characterized how it will perform if you try
15+
to 'begin' more than one.
16+
17+
For this example, you'll need:
18+
BlackBoard Artemis (or any Artemis board): https://www.sparkfun.com/products/15332
19+
Qwiic Accel: https://www.sparkfun.com/products/14587
20+
Qwiic Breadboard cable: https://www.sparkfun.com/products/14425
21+
22+
Hardware Connections:
23+
Connect the Qwiic cable to the Accel
24+
Plug the male pins into the following pins on the BlackBoard Artemis:
25+
Red -> 3.3V
26+
Black -> GND
27+
Yellow -> SCK
28+
Blue -> MISO
29+
*/
30+
31+
#include <Wire.h>
32+
33+
//Create a TwoWire object that uses a given IOMaster
34+
TwoWire myWire(0); //Will use pads 5/6, pins labeled SCK/MISO on BlackBoard Artemis
35+
//TwoWire myWire(1); //Will use pads 8/9
36+
//TwoWire myWire(2); //Will use pads 25/27, pins labeled D6/RX1 on BlackBoard Artemis
37+
//TwoWire myWire(3); //Will use pads 42/43
38+
//TwoWire myWire(4); //Will use pads 39/40, pins labeled SCL/SDA on BlackBoard Artemis
39+
//TwoWire myWire(5); //Will use pads 48/49, pins labeled TX0/RX0 on BlackBoard Artemis
40+
41+
#include "SparkFun_MMA8452Q.h" // Click here to get the library: http://librarymanager/All#SparkFun_MMA8452Q
42+
MMA8452Q accel; // Create instance of the MMA8452 class
43+
44+
void setup() {
45+
Serial.begin(9600);
46+
Serial.println("MMA8452Q on non-standard I2C port!");
47+
48+
myWire.begin();
49+
50+
//Here's the next trick. You need to pass this Wire port to your library.
51+
//SparkFun libraries allow any Wire port to be passed in. Other folk's libraries may not do this.
52+
if (accel.begin(myWire) == false) {
53+
Serial.println("Not Connected. Please check connections and read the hookup guide.");
54+
while (1);
55+
}
56+
}
57+
58+
void loop() {
59+
if (accel.available()) { // Wait for new data from accelerometer
60+
// Acceleration of x, y, and z directions in g units
61+
Serial.print(accel.getCalculatedX(), 3);
62+
Serial.print("\t");
63+
Serial.print(accel.getCalculatedY(), 3);
64+
Serial.print("\t");
65+
Serial.print(accel.getCalculatedZ(), 3);
66+
Serial.println();
67+
}
68+
}

0 commit comments

Comments
 (0)