-
Notifications
You must be signed in to change notification settings - Fork 5
/
APM2_6.ino
116 lines (93 loc) · 2.38 KB
/
APM2_6.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <SPI.h>
//LED output pins
const int ledBlue = 25;
const int ledYellow = 26;
const int ledRed = 27;
//SPI Bus SlaveSelect pins
const int imuSelect = 53;
const int pressureSelect = 40;
/*
_______________DataFlash(AT45DB161-MU) Pinout_______________
PJ1 = MOSI_DF = 14
PJ2 = SCK_DF = NA
PA6 = CS_DF = 28
PG0 = RST_DEF = 41
I assume these pins go to some SPI hardware...
*/
/*
_______________Magnetometer(HMC5883L) Pinout________________
SCL = PD0 = 21
SDA = PD1 = 20
This seems like the defualt bus
*/
/*
_______________Servo PPM Encoder Pinout______________________
Definitely a lot more going on in the circuit than I orignally thought.
ATMEGA32U4 ATMEGA2560
PPM_PD1 PA2
PPM_PD0 PA1
PPM_PC2 => Throws switch for whole system
This pin is on the ATMEGA32U4
This will throw the connections for pins
RX0-1 ____PPM_TX (Normally Open)
ATMEGA2560_PE0 (RX?)_____|____3DR_RX (Normally Closed)
TX0-O ____PPM_RX (Normally Open)
ATMEGA2560_PE1 (TX?)_____|____3DR_TX (Normally Closed)
*/
/*
_______________Servo Outputs_________________________________
OUT1 = PB6 = 12
OUT2 = PB5 = 11
OUT3 = PH5 = 8
OUT4 = PH4 = 7
OUT5 = PH3 = 6
OUT6 = PE5 = 3
OUT7 = PE4 = 2
OUT8 = PE3 = 5
*/
const int servo_count = 8;
const int servo_pins[8] = {12,11,8,7,6,3,2,5};
/*
_______________Extra IO_______________________________________
IO1 = PF0 = ADC0
IO2 = PF1 = ADC1
IO3 = PF2 = ADC2
IO4 = PF3 = ADC3
IO5 = PF4 = ADC4
IO6 = PF5 = ADC5
IO7 = PF6 = ADC6
IO8 = PF8 = ADC7
IO9 = PK0 = ADC8
*/
const int io_count = 9;
const int io_pins[9] = {A0, A1, A2, A3, A4, A5, A6, A7, A8};
void setup () {
Serial.begin(9600);
pinMode(ledBlue, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledRed, OUTPUT);
digitalWrite(ledBlue, HIGH);
digitalWrite(ledYellow, HIGH);
digitalWrite(ledRed, HIGH);
pinMode(imuSelect, OUTPUT);
pinMode(pressureSelect, OUTPUT);
digitalWrite(imuSelect, HIGH);
digitalWrite(pressureSelect, HIGH);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setDataMode(SPI_MODE3);
delay(100);
}
void loop () {
byte resultat = spi_read(0x3B | 0b10000000);
Serial.println(resultat, BIN);
delay(1000);
}
byte spi_read(byte read_command) {
digitalWrite(imuSelect, LOW);
SPI.transfer(read_command);
byte miso_data = SPI.transfer(0);
digitalWrite(imuSelect, HIGH);
return miso_data;
}