Results 1 to 2 of 2

Thread: Attempting to send voltage to teenssy board via Arduino C++.

  1. Question Attempting to send voltage to teenssy board via Arduino C++.

    Hey all,

    I am still new to programing with arduino and teensy for that matter, so apologies in advance if the questions seems a bit straight forward.

    I am attempting to develop a simple RC car using the teensy as a medium to send input to the motors.

    I've written this basic script to send a current to a teensy board (3.6) specifically to ports
    (8, 2, 9, 10) (11, 5, 12, 24) (28, 7, 29, 30) (25, 6, 26, 27)

    For instance ports (8, 2, 9, 10) are responsible for controlling the front right motor.

    Illustration below for ports
    Click image for larger version. 

Name:	teensy.jpg 
Views:	59 
Size:	105.9 KB 
ID:	7660

    The issue with the code below is all the value return a 0. As shown in the image below.

    Click image for larger version. 

Name:	teensy2.jpg 
Views:	59 
Size:	36.0 KB 
ID:	7661

    Code:
    // Set motor Settings // 
    //front_right_motor
    #define DIR_FR 8
    #define PWM_FR 2
    #define ENCA_FR 9
    #define ENCB_FR 10
    
    //PID gain declaration 
    //can try to change the kp and ki value by tuning 
    double kp=1;
    double ki=1000;//1000;
    double kd=0;
    
    //set point declaration reference 
    double setpointLeft=0;
    double setpointRight=0;
    
    // Variable declaration & Initialization for PID Calculation
    // FR Settings
    double errorFR=0; 
    double iFR=0; 
    double errorFR_prior=0; 
    double iFR_prior=0; 
    double dFR=0; 
    double PID_FR=0;
    
    //Encoder count values
    volatile long FrontRightCount = 0;
    volatile long FrontRightCounts = 0;
    
    //declaring variables used in sampling time calculation
    float t1=0;
    float t2=0;
    float dt=0;
    volatile float vFR=0;
    
    // Function declaration for inputting pwm signal to the motor
    void motorFR(double pid);
    
    void setup() 
    {
        // Setup for Front Right Motor
        pinMode(PWM_FR,OUTPUT);
        pinMode(DIR_FR,OUTPUT);
    
        digitalWrite(DIR_FR,LOW);
        pinMode(ENCA_FR, INPUT);
        digitalWrite(ENCA_FR, HIGH); //pullup
        pinMode(ENCB_FR, INPUT);
        digitalWrite(ENCB_FR, HIGH); //pullup
    
        attachInterrupt(ENCA_FR, front_right_encoderA_ISR, CHANGE);
        attachInterrupt(ENCB_FR, front_right_encoderB_ISR, CHANGE);
    }
    
    void loop()
    {
        t1=micros();
        // put your main code here, to run repeatedly:
        if(d<2500000)
        {
            digitalWrite(DIR_FR,HIGH);
            analogWrite(PWM_FR,0);
        }
        else
        {
            digitalWrite(DIR_FR,HIGH);
            analogWrite(PWM_FR,50); 
        }
    
        d++;
    
        delay(100);
        Serial.print(FrontRightCount); Serial.print("\t");
    
        t2=micros();
        dt=(t2-t1)/1000000;
        Serial.println(dt);
    
        vFR=((float)FrontRightCount/980.0)*2.0*M_PI*0.127/dt;
    
        FrontRightCount = 0;
    
        Serial.print(vFR); Serial.print("\t");
    }
    
    void front_right_encoderA_ISR() 
    {
        if (digitalRead(ENCA_FR)==HIGH)
        {
            if(digitalRead(ENCB_FR)==LOW)
                FrontRightCount++;
            else
                FrontRightCount--;
        }
        else
        {
            if(digitalRead(ENCB_FR)==HIGH)
                FrontRightCount++;
            else
                FrontRightCount--;
        }
    }
    
    void front_right_encoderB_ISR() 
    {
        if (digitalRead(ENCB_FR)==HIGH)
        {
            if(digitalRead(ENCA_FR)==HIGH)
                FrontRightCount++;
            else
                FrontRightCount--;
        }
        else
        {
            if(digitalRead(ENCA_FR)==LOW)
                FrontRightCount++;
            else
                FrontRightCount--;
        }
    }
    I'm not sure what I should do now exactly the code seems correct but the loop does not return any value.

  2. #2

    Re: Attempting to send voltage to teenssy board via Arduino C++.

    I suggest the best forum to ask this in is https://forum.pjrc.com/forums/3-Tech...-amp-Questions

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question: Using Arduino IDE 1.8.1 and Can't See My ArbotiX-M on the Board List
    By SoCalTechTeacher in forum Arbotix, Microcontrollers, Arduino
    Replies: 16
    Last Post: 07-03-2017, 11:39 AM
  2. Question(s) setup arduino ide for arbotix board
    By gorhgorh in forum Software and Programming
    Replies: 8
    Last Post: 04-16-2015, 05:08 PM
  3. PC or Arduino, or Android board for humanoid control?
    By wthierry in forum Humanoids, Walkers & Crawlers
    Replies: 5
    Last Post: 07-02-2014, 11:46 PM
  4. powering and arduino board
    By vini_i in forum Arbotix, Microcontrollers, Arduino
    Replies: 3
    Last Post: 08-12-2013, 03:54 PM
  5. Which Arduino Board
    By cross1933 in forum Arbotix, Microcontrollers, Arduino
    Replies: 14
    Last Post: 04-25-2009, 06:26 PM

Tags for this Thread

Posting Permissions

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