web analytics

photorestor on the Phoenex Bread

Home Forums Troubleshooting photorestor on the Phoenex Bread

This topic contains 2 replies, has 2 voices, and was last updated by  Phoenard-Team March 16, 2016 at 1:47 pm.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #957 Reply

    gekophetweb
    Participant

    Hi
    I’ve recently found time to play around with the phoenard but have some difficulty with a photo-resistor on the Phoenex Bread. It works fine when I have it linked to my computer by micro USB.
    The moment I remove the micro-USB cable or don’t have the micro-USB cable plugged in when starting the sketch it won’t read the photo-resistor.
    Do you have any idea why it won’t read the photo-resistor when it’s not connected to my computer?

    edit:
    Though apparently when it’s connected to my computer it and I’m reading the photoresistor value,it keeps on switching between min and max value when I do nothing, and it’s fixed when I wave my hand over the photoresistor.
    photo and sketch code provided.

    #include "Phoenard.h"
    
    // The size of a color selectable box
    #define BOXSIZE 38
    // The top-offset of the color selectable boxes
    #define BOXOFFSET 10
    
    color_t oldcolor;     // Old color selected, used for detecting color change
    color_t currentcolor; // Current color to use for drawing
    int box_x;            // X-coordinate of the color selection boxes
    int width, height;    // Width and height of the screen
    PressPoint last;      // Last point pressed down on the screen
    boolean hasLast;      // Whether the use has pressed down before
    
    int lightLevel, high = 0, low = 1023;
    
    void setup() {
      // put your setup code here, to run once:
      lightLevel = 122;
      pinMode(4, OUTPUT);
      pinMode(A2, INPUT);
      display.setTextSize(1);
      display.setCursor(40, 80);
      display.print("LED test \n");
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      display.setCursor(40, 120);
      display.setTextColor(WHITE, BLACK);
    
      lightLevel = analogRead(A2);
    
      if (lightLevel < low)
      {
        low = lightLevel;
      }
      
      if (lightLevel > high)
      {
        high = lightLevel;
      }
      
      lightLevel = map(lightLevel, low+30, high-30, 0, 255);
      lightLevel = constrain(lightLevel, 0, 255);
    
      display.print(lightLevel);
      display.printPadding(10); 
    
      if(lightLevel > 200)
        analogWrite(4, 0); 
      else
        analogWrite(4, 255); 
      
      
    }

    Jaap

    #960 Reply

    gekophetweb
    Participant

    apparently it also works when I provide it power through USB-micro, not just connected to my computer.
    I tested this on my arduino and it works fine over there.

    #963 Reply

    Phoenard-Team
    Keymaster

    It looks like you are using the 5V to provide power to the photoresistor circuit. The 5V line is direct USB voltage supply, so if USB is not connected there is no power coming from here. The main board is a 3V3 reference, so you should use the VCC or 3V3 line instead of the 5V line. Perhaps slightly confusing, considering most Arduino boards are 5V referenced.

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: photorestor on the Phoenex Bread
Your information:




58 + = 65