First of all, Merry Christmas to all, I hope you're having a wonderful time. I sure am, finally getting to work on a long term project of mine.
I've got a teensy 3.2 that will power up and run my code from USB.
It will also run the code when it is powered by 5V to Vin and GND.
When I plug it into my breakout board, which feeds 5V to Vin and GND, I get nothing.
Im assuming i've made an error in my breakout board, so im hoping one of the wise folk here will be able to spot my error.
Here is my schematic.
Here is a link to the live schematic
And here is a copy of the code im running, but I don't think it really matters.
I've got a teensy 3.2 that will power up and run my code from USB.
It will also run the code when it is powered by 5V to Vin and GND.
When I plug it into my breakout board, which feeds 5V to Vin and GND, I get nothing.
Im assuming i've made an error in my breakout board, so im hoping one of the wise folk here will be able to spot my error.
Here is my schematic.
Here is a link to the live schematic
And here is a copy of the code im running, but I don't think it really matters.
Code:
#include <TimerOne.h>
#include "SBUS.h"
// a SBUS object, which is on Teensy hardware
// serial port 1
SBUS Transmit(Serial1);
//Channel Map
//CH01: Roll (pin [A13])
uint16_t CH01 = A13;
int CH01Value = 0;
//CH02: Pitch (pin [A11])
uint16_t CH02 = A11;
int CH02Value = 0;
//CH03: Throttle (pin 30 [A19])
uint16_t CH03 = A19;
int CH03Value = 0;
//CH04: Yaw (pin 15 [A1])
uint16_t CH04 = A1;
int CH04Value = 0;
//CH05: Mode selection switches momentary digital pins - 2 on Left Side, 4 on Right Side:
//pin 33 [RTL - Left Side]
int CH05Mode1 = 33;
int Mode1Value = 0;
int Mode1LED = 22;
//pin 18 [LAND - Left Side]
int CH05Mode2 = 18;
int Mode2Value = 0;
int Mode2LED = 23;
//pin 26 [STABILISED - Right Side]
int CH05Mode3 = 26;
int Mode3Value = 0;
int Mode3LED = 6;
//pin 9 [POSITION HOLD - Right Side]
int CH05Mode4 = 9;
int Mode4Value = 0;
int Mode4LED = 5;
//pin 25 [LOITER - Right Side]
int CH05Mode5 = 25;
int Mode5Value = 0;
int Mode5LED = 4;
//pin 24 [AUTO - Right Side]
int CH05Mode6 = 24;
int Mode6Value = 0;
int Mode6LED = 3;
//CH06: Camera pitch - Left Slider (pin 29 [A18])
uint16_t CH06 = A18;
int CH06Value = 0;
//CH07: Arm [Motor Interlock] (pin 32)
int CH07 = 32;
int CH07Value = 0;
int CH07LED = 20;
//CH08: Brake (pin 17)
int CH08Brake = 17;
int CH08Value = 0;
int CH08LED = 21;
//CH09: Camera Shutter - Right 3-way Switch (pin [A14])
uint16_t CH09 = A14;
int CH09Value = 0;
//CH10: Left 2-way Switch (pin 16)
int CH10 = 16;
int CH10Value = 0;
//CH11: Left 3-way Switch (pin 14 [A0])
uint16_t CH11 = A0;
int CH11Value = 0;
//CH12: Right 2-way Switch (pin 10)
int CH12 = 10;
int CH12Value = 0;
//CH13: Left Slider (pin 29 [A18])
uint16_t CH13 = A18;
int CH13Value = 0;
//CH14: Right Slider (pin [A12])
uint16_t CH14 = A12;
int CH14Value = 0;
//CH15: Left Twist (pin 31 [A20])
uint16_t CH15 = A20;
int CH15Value = 0;
//CH16: Right Twist (pin [A10])
uint16_t CH16 = A10;
int CH16Value = 0;
const int ledPin = 13; //just a heartbeat to show that the code is going
void setup() {
pinMode(20, OUTPUT); // LED
pinMode(21, OUTPUT); // LED
pinMode(22, OUTPUT); // LED
pinMode(23, OUTPUT); // LED
pinMode(6, OUTPUT); // LED
pinMode(5, OUTPUT); // LED
pinMode(4, OUTPUT); // LED
pinMode(3, OUTPUT); // LED
pinMode(33, INPUT_PULLUP); // Momentary Switch
pinMode(18, INPUT_PULLUP); // Momentary Switch
pinMode(26, INPUT_PULLUP); // Momentary Switch
pinMode(9, INPUT_PULLUP); // Momentary Switch
pinMode(25, INPUT_PULLUP); // Momentary Switch
pinMode(24, INPUT_PULLUP); // Momentary Switch
pinMode(32, INPUT_PULLUP); // Momentary Switch
pinMode(17, INPUT_PULLUP); // Momentary Switch
pinMode(16, INPUT_PULLUP); // Momentary Switch
pinMode(10, INPUT_PULLUP); // Momentary Switch
pinMode(ledPin, OUTPUT);
// serial to display the channel commands for debugging
Serial.begin(115200);
// begin the SBUS communication
Transmit.begin();
// setup the analog read resolution to 16 bits
analogReadResolution(16);
// setup an interrupt to send packets every 9 ms
Timer1.initialize(9000);
Timer1.attachInterrupt(sendSBUS);
}
void loop() {
//heartbeat timing
digitalWrite(ledPin, HIGH); // set the LED on
delay(200); // wait for a 0.2 seconds
digitalWrite(ledPin, LOW); // set the LED on
delay(100); // wait for a 0.1 seconds
digitalWrite(ledPin, HIGH); // set the LED on
delay(200); // wait for a 0.2 seconds
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
// reads analog and digital inputs and sends an SBUS packet */
void sendSBUS() {
float scaleFactor = 1639.0f / 65535.0f;
float bias = 172.0f;
uint16_t channels[16];
CH01 = analogRead(CH01); // read the analog input
CH01Value = (uint16_t)(((float)CH01) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH01: ");
Serial.print(CH01Value); // print the channel command (172-1811)
Serial.print("\t");
CH02 = analogRead(CH02); // read the analog input
CH02Value = (uint16_t)(((float)CH02) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH02: ");
Serial.print(CH02Value); // print the channel command (172-1811)
Serial.print("\t");
CH03 = analogRead(CH03); // read the analog input
CH03Value = (uint16_t)(((float)CH03) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH03: ");
Serial.print(CH03Value); // print the channel command (172-1811)
Serial.print("\t");
CH04 = analogRead(CH04); // read the analog input
CH04Value = (uint16_t)(((float)CH04) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH04: ");
Serial.print(CH04Value); // print the channel command (172-1811)
Serial.print("\t");
CH06 = analogRead(CH06); // read the analog input
CH06Value = (uint16_t)(((float)CH06) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH06: ");
Serial.print(CH06Value); // print the channel command (172-1811)
Serial.print("\t");
CH09 = analogRead(CH09); // read the analog input
CH09Value = (uint16_t)(((float)CH09) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH09: ");
Serial.print(CH09Value); // print the channel command (172-1811)
Serial.print("\t");
CH11 = analogRead(CH11); // read the analog input
CH11Value = (uint16_t)(((float)CH11) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH11: ");
Serial.print(CH11Value); // print the channel command (172-1811)
Serial.print("\t");
CH13 = analogRead(CH13); // read the analog input
CH13Value = (uint16_t)(((float)CH13) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH13: ");
Serial.print(CH13Value); // print the channel command (172-1811)
Serial.print("\t");
CH14 = analogRead(CH14); // read the analog input
CH14Value = (uint16_t)(((float)CH14) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH14: ");
Serial.print(CH14Value); // print the channel command (172-1811)
Serial.print("\t");
CH15 = analogRead(CH15); // read the analog input
CH15Value = (uint16_t)(((float)CH15) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH15: ");
Serial.print(CH15Value); // print the channel command (172-1811)
Serial.print("\t");
CH16 = analogRead(CH16); // read the analog input
CH16Value = (uint16_t)(((float)CH16) * scaleFactor + bias); // linearly map the analog measurements (0-65535) to the SBUS commands (172-1811)
Serial.print("CH16: ");
Serial.print(CH16Value); // print the channel command (172-1811)
Serial.print("\t");
Serial.println();
// write the SBUS packet to an SBUS compatible servo
Transmit.write(&channels[0]);
}