Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: SBUS library - not reading analog pin

Threaded View

  1. #1

    SBUS library - channel value not changing with analog input

    I Have this code working on my teensy3.2, but my analog input does nothing.
    When I view the serial monitor I only get these values bouncing back and forth:
    CH01: 1807
    CH01: 172
    CH01: 1807
    CH01: 172
    CH01: 1808

    Here's my code, I know its not the way Brian (brtaylor) has suggested to use analog inputs to generate the sbus signal (Link here), but I also need to use digital inputs mixed in with my analog inputs, and im not sure how to keep all my channels in order, so im trying it this way.

    Please note that the void loop "heartbeat" is just there so I can see that the teensy is actually operating

    #include <TimerOne.h>
    #include "SBUS.h"
    // output SBus on serial port 1
    SBUS Transmit(Serial1);
    //CH01: Roll (pin [A13])
    uint16_t CH01 = A13;
    int CH01Value = 0;
    const int ledPin = 13; //just a heartbeat to show that the code is going
    void setup() {
        pinMode(ledPin, OUTPUT);
      // serial to display the channel commands for debugging
      // begin the SBUS communication
      // setup the analog read resolution to 16 bits
      // setup an interrupt to send packets every 9 ms
    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)
      // write the SBUS packet to an SBUS compatible servo
    My end goal is to output 15 sbus channels, made up of 10 analog inputs and 10 digital inputs.
    The order of those inputs is not all analog then digital, they are all mixed in together.
    Within that 10 digital inputs I have 6 momentary switches that are mapped to a single channel (Channel 5). I want to be able to output a predefined value dependent on which switch is pressed, and maintain that value until another switch is pressed.

    Im still a noob at coding anything (as my code shows), but I started this project a long time ago, and decided to pick it back up myself over this holiday period.
    There's obviously a number of ways to read the inputs and generate the sbus output, and I'd like to do it the most efficient way so any suggestions will be appreciated.

    Here's a pic of what im basically trying to do
    Click image for larger version. 

Name:	Concept layout.jpg 
Views:	18 
Size:	65.7 KB 
ID:	12494
    Last edited by Geekness; 01-03-2018 at 12:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts