Project help: potentiometer, oled, servo (is it my code or hardware?)

I am trying to have a oled display(ROHS not sure the model but its tiny) my potentiometer reading from 0 to 180. I can do that part perfectly fine. I then want my potentiometer to control my continuous servo (FS5103R), which I can get to work fine. What doesn’t work is when I hook them all together, that is getting my potentiometer reading on the oled display & writing the servo speed.

Is it that I am not balancing my power correctly? I only have one resistor connected to the potentiometer so I can get an even reading. I think it could either be this OR

in my code, when I initialize the oled screen with oled.begin(), that’s when my servo ceases to work. If I comment that line out, the servo works but not the screen. I appreciate any help :slight_smile:

The servo may be pulling too much power and causing the voltage to drop to the point that nothing else works.

Try powering the servo from a higher current power source and see if you have the same problem.

1 Like

I connected an external power source and I’m still getting the same issue. The servo makes a noise and it’s getting power. I could use another Photon, but I’m not sure if I could grab a variable I expose from one Photon and use it in a program for the other.

Here’s the code. I’m using the oled library.

/*


    MicroOLED ------------- Photon
      GND ------------------- GND
      VDD ------------------- 3.3V (VCC)
    D1/MOSI ----------------- A5 (don't change)
    D0/SCK ------------------ A3 (don't change)
      D2
      D/C ------------------- D6 (can be any digital pin)
      RST ------------------- D7 (can be any digital pin)
      CS  ------------------- A2 (can be any digital pin)


*******************************************************************************/
#include "SparkFunMicroOLED/SparkFunMicroOLED.h"  // Include MicroOLED library
#include "math.h"

//////////////////////////////////
// MicroOLED Object Declaration //
//////////////////////////////////
// Declare a MicroOLED object. If no parameters are supplied, default pins are
// used, which will work for the Photon Micro OLED Shield (RST=D7, DC=D6, CS=A2)
Servo myServo;
MicroOLED oled;
//MicroOLED oled(MODE_I2C, D7, 0);    // Example I2C declaration RST=D7, DC=LOW (0)


int pot = A1;
int potRead;

void setup()
{
  myServo.attach(A4);
  myServo.write(160);

  pinMode(pot, INPUT);
  oled.begin();
  oled.clear(ALL); // Clear the display's internal memory
  oled.display();  // Display what's in the buffer (splashscreen)
  delay(1000);     // Delay 1000 ms
  //randomSeed(analogRead(A0) + analogRead(A1));
}

void loop()
{
   getPotReadAndDisplayOnScreen();
}

int pixelExample(int potRead)
{
  printTitle(potRead, 1);
}

void getPotReadAndDisplayOnScreen(){
   int potRead =  (analogRead(pot) / 20.8777) - 16;
   pixelExample(potRead);    
}

void printTitle(int title, int font)
{
  int middleX = oled.getLCDWidth() / 2;
  int middleY = oled.getLCDHeight() / 2;

  oled.clear(PAGE);
  oled.setFontType(font);
  // Try to set the cursor in the middle of the screen
  oled.setCursor(middleX - (oled.getFontWidth() * (2)),
                 middleY - (2)); 
  // Print the title:
  oled.print(title);
  oled.display();
  delay(1500);
  oled.clear(PAGE);
}

The specs for that servo say it should be powered with 4.8 to 6 volts. Are you doing that, or are you using 3.3 volts? If you’re using an external power supply, what is its current output?

1 Like

My external power supply was 3volts. I’ll add some more voltage and get back to you! Thanks

I think it’s the code. I hooked up two 3v batteries to get 6v and same issue. The servo gets power, but it’s not recognizing it as an output. I think may oled.begin() is blocking the other code?

Post a picture of what you have going on over there.

Is the OLED communicating over I2C?

The Sparkfun display defaults to SPI for communications (it can also do i2c and parallel) and that used pin A4 as MISO, so you can’t use that pin for the servo.

You can use these pins with a conflict on a Photon for Servo: WKP, RX, TX, D0, D1, D2, D3