Free 186 More Best Homemade Tools eBook:  
New: 300+ fresh build posts/day from 275 forums → BuildThreads.com

User Tag List

Results 1 to 10 of 21

Thread: rotary table driven by stepper motor controlled by 2 Arduino's

Threaded View

  1. #7
    Supporting Member metric_taper's Avatar
    Join Date
    Mar 2017
    Location
    Marion, Iowa
    Posts
    760
    Thanks
    281
    Thanked 410 Times in 266 Posts

    metric_taper's Tools
    Quote Originally Posted by thehomeengineer View Post
    Encoder Arduino code using Arduino Nano


    #include <SPI.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
    #include <Wire.h>


    #define SCREEN_WIDTH 128 // OLED display width, in pixels
    #define SCREEN_HEIGHT 32 // OLED display height, in pixels




    // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
    #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


    const byte interrupt = 2;
    const byte interruptB = 3;
    const int encoder1PinA = 2; // encoder channel A,B (interupt pins)
    const int encoder1PinB = 3;
    float Pos1deg = 0;




    volatile float encoder1Pos = 0; //ticks of encoder will change, initial number is zero




    void setup()
    {
    Wire.setClock(400000);
    // Serial.begin(9600);
    if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    //Serial.println(F("SSD1306 allocation failed"));
    for (;; // Don't proceed, loop forever
    }
    attachInterrupt(0, runEncoder1, RISING ); // encoder pin on interrupt 0 >>(pin 2 on arduino)


    }


    void loop()
    {


    float Pos1;
    uint8_t oldSREG = SREG;


    cli();
    Pos1 = encoder1Pos;
    SREG = oldSREG;
    static int oldPos1;
    if (Pos1 != oldPos1) {
    oldPos1 = Pos1;
    }
    I thought there would be an ISR routine for the attachInterrupt. Am I missing something in how arduino code works?

  2. The Following 3 Users Say Thank You to metric_taper For This Useful Post:

    emu roo (Sep 25, 2025), Paul Jones (Jan 15, 2020), thehomeengineer (Jan 15, 2020)

Thread Information

Users Browsing this Thread

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

Bookmarks

Posting Permissions

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