Teensy 3.6 + Radio Control
The Radio Control receiver was the main reason for me to investigate microcontrollers. I needed a way to read the signal that I was transmitting from a Radio Control transmitter. I discovered about PWM signals and that they could be read by microcontrollers. I started small with the Arduino Uno, but have branched out since. Reading a radio control receiver is useful as I can take control of the robot if it is heading into danger.
Video
Please click thumbnail image to start the video



Photo


Sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2019 https://www.roboticboat.uk | |
// 560077e6-ccb2-4304-9431-97d5b92b1d9e | |
// | |
// This program is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by | |
// the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// | |
// This program is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// GNU General Public License for more details. | |
// | |
// You should have received a copy of the GNU General Public License | |
// along with this program. If not, see <https://www.gnu.org/licenses/>. | |
// These Terms shall be governed and construed in accordance with the laws of | |
// England and Wales, without regard to its conflict of law provisions. | |
int ch1; | |
int ch2; | |
int ch3; | |
int ch4; | |
void setup() | |
{ | |
// Keep the User informed | |
Serial.begin(9600); | |
// Setup radio control input pins | |
pinMode(35, INPUT); | |
pinMode(36, INPUT); | |
pinMode(37, INPUT); | |
pinMode(38, INPUT); | |
} | |
void loop() | |
{ | |
// Read the pulse width of each channel | |
ch1 = pulseIn(35, HIGH, 20000); | |
ch2 = pulseIn(36, HIGH, 20000); | |
ch3 = pulseIn(37, HIGH, 20000); | |
ch4 = pulseIn(38, HIGH, 20000); | |
// Map the value to the range 0 to 180 which is what radio control servos like | |
ch1 = map(ch1,1000,2000,0,180); | |
ch2 = map(ch2,1000,2000,0,180); | |
ch3 = map(ch3,1000,2000,0,180); | |
ch4 = map(ch4,1000,2000,0,180); | |
// Print data to Serial Monitor window | |
Serial.print("$RC,"); | |
Serial.print(ch1); | |
Serial.print(","); | |
Serial.print(ch2); | |
Serial.print(","); | |
Serial.print(ch3); | |
Serial.print(","); | |
Serial.println(ch4); | |
} |