Recent Posts

Pages: [1] 2 3 ... 10
1
Displays / Re: Question regarding ssd1306...
Last post by CatDadJynx - Today at 01:43 am
Alas, still no luck. The wiring diagram in my last post is reflective of my current setup, using two 10K resistors. Here are the two programs ive been trying each time (both yielding the same results).

Program 1:
Code: [Select]


/***************************************************
  This is a library example for the MLX90614 Temp Sensor

  Designed specifically to work with the MLX90614 sensors in the
  adafruit shop
  ----> https://www.adafruit.com/products/1748
  ----> https://www.adafruit.com/products/1749

  These sensors use I2C to communicate, 2 pins are required to
  interface
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_MLX90614.h>

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup() {
  u8g2.begin();
  u8g2.enableUTF8Print();
  mlx.begin();
}

void loop() {
  u8g2.clearBuffer();                                 // update
  u8g2.setFont(u8g2_font_5x7_tf);
  u8g2.setCursor(0, 15);
  u8g2.print("Ambient = "); u8g2.print(mlx.readAmbientTempC());
  u8g2.setCursor(0, 25);
  u8g2.print("*C\tObject = "); u8g2.print(mlx.readObjectTempC()); u8g2.println("*C");
  u8g2.setCursor(0, 35);
  u8g2.print("Ambient = "); u8g2.print(mlx.readAmbientTempF());
  u8g2.setCursor(0, 45);
  u8g2.print("*F\tObject = "); u8g2.print(mlx.readObjectTempF()); u8g2.println("*F");
  u8g2.println();
  u8g2.sendBuffer();
  delay(500);
}


Program 2:

Code: [Select]
#include <Wire.h>
#include <Adafruit_MLX90614.h>

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

const long screenInterval = 1000;           // interval at which to buffer (milliseconds)
unsigned long sensorInterval = 500;
unsigned long screenPreviousMillis = 0;
unsigned long sensorPreviousMillis = 0;


void setup() {
  mlx.begin();
  u8g2.begin();
  u8g2.enableUTF8Print();
}


void loop()
{
  unsigned long sensorCurrentMillis = millis();
  static double oldAmbientC = 500;
  static double oldObjectC = 500;                     // retains values
  if (sensorCurrentMillis - sensorPreviousMillis >= sensorInterval) {
    sensorPreviousMillis = sensorCurrentMillis;             // for next read
    double AmbientC = mlx.readAmbientTempC();
    double ObjectC = mlx.readObjectTempC();
    double AmbientF = mlx.readAmbientTempF();
    double ObjectF = mlx.readObjectTempF();
    if (AmbientC != oldAmbientC || ObjectC != oldObjectC) { // ?changed
      oldAmbientC = AmbientC;                             // remember
      oldObjectC = ObjectC;
      u8g2.clearBuffer();                                 // update
      u8g2.setFont(u8g2_font_5x7_tf);
      u8g2.setCursor(0, 15);
      u8g2.print("Ambient = "); u8g2.print(AmbientC);
      u8g2.setCursor(0, 25);
      u8g2.print("*C\tObject = "); u8g2.print(ObjectC); u8g2.println("*C");
      u8g2.setCursor(0, 35);
      u8g2.print("Ambient = "); u8g2.print(AmbientF);
      u8g2.setCursor(0, 45);
      u8g2.print("*F\tObject = "); u8g2.print(ObjectF); u8g2.println("*F");
      u8g2.println();
      u8g2.sendBuffer();                                  // draw the screen
    }
  }
}


In the meantime i will be working on a way to measure voltage, so hopefully i can shed more light on my i2c setup.
2
You should keep in mind that all is not Rosy in the land of switching regulators :(

Switching Regulators are typically 80 to 90% efficient "at the rated output".   At very low currents you might find the switching regulators do not provide as much of an efficiency increase at one might think.

I mention this because your original question mentioned 100 ma.   Doing a quick search of ebay the lowest current switching device I found was 2Amp.

if 90% efficient the losses for a 2A switcher would be approx  (1.0-0.9) * 12 * 2 = 2.4 watts (at the rated output of 2A)

If 3/4 of that loss was proportional to current then the remaining 1/4 occurs at any output current.  That "idleing loss might be 2.4 / 4 = 0.6 watts.


In your example the loss you would have is (12-5) *0.1 = 0.7 watts.   So the switching power supply MIGHT only save you 0.1 watts.


Now there are likely lower current switching regulators that are more efficient at low loads.  And my numbers are mostly "off hand" and not based on any specific specifications or measurement.   My goal is to warn you to look at the specifications for any devices you might want to use and realize at low power levels a switching regulator might not be the best solution.



3
General Electronics / Re: Quick Question, about a Re...
Last post by MAS3 - Today at 01:37 am
Hi.

That is a switch mode regulator, it requires some external components to do it's thing.
But you found that on the 1st. page of the datasheet, right ?
To use this part, you also need to use the accompanying parts, either from the source board or buy new ones.
The datasheet also tells you how to do calculations so you will get to the 3.3 volts.

But if you have to ask about that, i'd rather advise you to get a module doing this for you.
So search for "adjustable voltage regulator module"
It will have a potentiometer that allows you to set the desired output voltage, and not be too large in size.
It'll set you back some US$ 2 plus shipping, so that would be the smarter thing to do.
And way faster than learning and developing the power supply you want it to be.

I'm all for learning and teaching about how things work and are supposed to be done.
But that's not in all cases the best advice to give.
So if you have time to learn about this and still want to go that path, you'll be welcome to do so.
Else just order one of these modules and go on with your project next weekend (or next month if you order from China).
4
There were a number of error.  

For a start you have an extra setup() and loop() at the top.  It looks like you pasted the sketch into the loop() function of the default 'minimal' sketch.

Second, the ACTUAL setup() is missing ") {"  after the "void setup(".  That caused the pinMode error:  It looked like you were putting pinMode(ButtonPin, INPUT); into the argument list of the (second) setup() function.

Third, the ACTUAL loop() function is missing the opening '{'.

Forth,  the array index on 'display' got stripped out of your sketch in two places.  Probably because when you post a sketch in the forum the 'i' in square brackets looks just like an "Italics" tag.

Fifth:  Somehow you got:
Code: [Select]
  display


   = 0x00; // the colon is off

 where you appear to want 
Code: [Select]
  display[0]  = 0x00; // the colon is off

And finally, you have an extra '}' at the end of your sketch.


After fixing those problems and reformatting you get:
Code: [Select]
// note that the backlight draws 3.5 ma and can be run directly from the arduino


#include <SPI.h>


//   0     1     2     3     4     5     6     7     8     9    -
const uint8_t nums[] =
{
  0xEE, 0x22, 0x7C, 0x76, 0xB2, 0xD6, 0xDE, 0x62, 0xFE, 0xF6, 0x10
};
const uint8_t dot = 0x01;
bool column = true;
uint8_t display[5];


int GearPin = 0;    // The Gear "pink" wire is connected to analog pin 0
int BatteryPin = 2;    // The Battery wire is connected to analog pin 2
int ButtonPin = 7;  // The button is connected to digital pin 7 as an input
// use a pull down resistor
int BLAPin = 5;  // The LCD display backlight is connected to digital pin 5 as a PWM output


int Gear = 0;
int ButtonPushCounter = 0;   // counter for the number of button presses
int ButtonValue = 0;       // current state of the button
int LastButtonValue = 0;    // previous state of the button
int GearValue;    // to store the value of the Gear
int BatteryValue;
int GrossedUpBatVal;
int ConvBatVal2;
int ConvBatVal = 1400;
void setup()
{
  pinMode(ButtonPin, INPUT);
  pinMode(BLAPin, OUTPUT);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV128); //this line slows the clock down
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE2);
  /*
        At CPOL=1 the base value of the clock is one (inversion of CPOL=0)
    For CPHA=0, data is captured on clock's falling edge and data is propagated on a rising edge.
         Mode          CPOL          CPHA
         0       0       0
         1       0       1
         2       1       0
         3       1       1
  */
  //Serial.begin(9600);
  // analogWrite values from 0 to 255
  analogWrite(BLAPin, 100);  // this turns on the backlighting at reduced level


}


void loop()
{


  delay(500); // repeat once per .5 second (change as you wish!)
  ButtonValue = digitalRead(ButtonPin);


  if (ButtonValue != LastButtonValue)
  {
    if (ButtonValue == HIGH)
    {
      ButtonPushCounter++;
    }
  }


  if (ButtonPushCounter % 2 == 0) //even number of pushes will show gear, odd will be battery
  {
    GearValue = analogRead(GearPin);
    GearValue = GearValue * 5 / 10.23; // this turns the volt value from 0 - 1023 to 0 - 5

    if (GearValue < 166)
    {
      Gear = 1;
    } //these volt values have been multiplied by 100


    if (GearValue >= 166 && GearValue < 218)
    {
      Gear = 2;
    }


    if (GearValue >= 218 && GearValue < 291.5)
    {
      Gear = 3;
    }


    if (GearValue >= 291.5 && GearValue < 372)
    {
      Gear = 4;
    }


    if (GearValue >= 372 && GearValue < 438.5)
    {
      Gear = 5;
    }


    if (GearValue >= 438.5 && GearValue < 480)
    {
      Gear = 6;
    }


    if (GearValue >= 480)
    {
      Gear = 10;
    }


    display[0] = 0x00;  // the colon is off and note that 00 in the display is really 0
    display[1] = 0x00;
    display[2] = 0x00;
    display[3] = nums[Gear];
    display[4] = 0x00;
    for (uint8_t i = 0; i < 5; i++)
      SPI.transfer(~display[i]);


    column = !column;
  }
  else
  {
    BatteryValue = analogRead(BatteryPin);
    GrossedUpBatVal = BatteryValue * 14.68 / 4.68; //gross up back to pre-divider value adjusted to give an accurate result
    ConvBatVal2 =  GrossedUpBatVal * 5 / 10.23;
    ConvBatVal = ConvBatVal * .9 + ConvBatVal2 * .1;
    display[0]  = 0x00; // the colon is off
    if (ConvBatVal < 1000)
    {
      display[1] = 0x00;
    }
    else
    {
      display[1] = nums[((ConvBatVal  - (ConvBatVal % 1000)) / 1000)];
    }


    display[2] = nums[((ConvBatVal % 1000) - (ConvBatVal % 100)) / 100]  | dot; //Hundreds with decimal point on
    display[3] = nums[((ConvBatVal % 100) - (ConvBatVal % 10)) / 10]; // Tens
    display[4] = nums[(ConvBatVal % 10)]; //Ones


    for (uint8_t i = 0; i < 5; i++)
      SPI.transfer(~display[i]);


    column = !column;
  }
}
5
Mostly because that's the way the compiler expects you to define a function. It's very particular about syntax and you just can't make up your own.
6
Quote
OK, but do clk and data "HAVE" to be the same?
No they can be different.

However, I would recommend using hardware SPI over the 'bit bashing ' approach as it is faster for updates. On an Uno, for example, this is only one set of pins. On other hardware there may be multiple SPI pins you can use.
7
Installation & Troubleshooting / Re: exit status 1
Last post by Ralphpdq - Today at 01:32 am
I "think" the JSON problem has been fixed but ...
Code: [Select]
"C:\Users\Ralph\AppData\Local\Temp\arduino_build_783981\libraries\ArduinoOTA\ArduinoOTA.cpp.o"
"C:\Users\Ralph\AppData\Local\Temp\arduino_build_783981\libraries\ESP8266mDNS\ESP8266mDNS.cpp.o"
"C:\Users\Ralph\AppData\Local\Temp\arduino_build_783981\libraries\DNSServer\DNSServer.a"
"C:\Users\Ralph\AppData\Local\Temp\arduino_build_783981/arduino.ar" -lhal -lphy -lpp -lnet80211 -llwip2 -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 -lstdc++ -lm -lc -lgcc -Wl,--end-group  "-L
C:\Users\Ralph\AppData\Local\Temp\arduino_build_783981"
xtensa-lx106-elf-gcc: error: C:\Users\Ralph\AppData\Local\Temp\arduino_build_783981\libraries\DNSServer\DNSServer.a: No such file or directory

Multiple libraries were found for "ESP8266mDNS.h"
 Used: C:\Users\Ralph\Documents\Arduino\libraries\ESP8266mDNS
 Not used: C:\Users\Ralph\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266mDNS
Multiple libraries were found for "DNSServer.h"
 Used: C:\Users\Ralph\Documents\Arduino\libraries\DNSServer
 Not used: C:\Users\Ralph\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\DNSServer
Using library ESPAsyncWebServer-master at version 1.2.0 in folder: C:\Users\Ralph\Documents\Arduino\libraries\ESPAsyncWebServer-master
Using library ESPAsyncTCP-master at version 1.2.0 in folder: C:\Users\Ralph\Documents\Arduino\libraries\ESPAsyncTCP-master
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\Ralph\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266WiFi
Using library ArduinoJson at version 5.13.2 in folder: C:\Users\Ralph\Documents\Arduino\libraries\ArduinoJson
Using library Hash at version 1.0 in folder: C:\Users\Ralph\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\Hash
Using library ESP8266httpUpdate at version 1.2 in folder: C:\Users\Ralph\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266httpUpdate
Using library ESP8266HTTPClient at version 1.1 in folder: C:\Users\Ralph\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ESP8266HTTPClient
Using library EEPROM at version 1.0 in folder: C:\Users\Ralph\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\EEPROM
Using library pubsubclient-master at version 2.6 in folder: C:\Users\Ralph\Documents\Arduino\libraries\pubsubclient-master
Using library ArduinoOTA at version 1.0 in folder: C:\Users\Ralph\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\ArduinoOTA
Using library ESP8266mDNS at version 1.1 in folder: C:\Users\Ralph\Documents\Arduino\libraries\ESP8266mDNS
Using library DNSServer at version 1.1.0 in folder: C:\Users\Ralph\Documents\Arduino\libraries\DNSServer
exit status 1
Error compiling for board Adafruit Feather HUZZAH ESP8266.


Where could I get DNSServer.a from?
Also do I need to do anything about the MUltiple Files found Used/Notused?

I copied all of the C:\Users\Ralph\Documents\Arduino\libraries\ from the GIT current Arduino Core build.
Ralph
8
Okay I figured it out.  I guess the tone() function fiddles with those registers and OR'ing them with a bit mask was leaving some of their bit values.  I changed:

Code: [Select]
  TCCR2A |= 0;
  TCCR2B |= 0x04; //prescaler set to 1/64
  OCR2A |= 0xFF;  //this can be adjusted later


to:

Code: [Select]
  TCCR2A = 0;
  TCCR2B = 0x04; //prescaler set to 1/64
  OCR2A = 0xFF;  //this can be adjusted later
9
Project Guidance / Re: Nixie tube scoreboard
Last post by CrossRoads - Today at 01:23 am
If you can build one of these up, then it would be not too hard to program it to display button push results instead of a running time.

https://www.nixieclock.biz/Store.html
10
Sensors / Re: I need a code that can det...
Last post by DeanElliottIT - Today at 01:21 am
Well this works with other sensors. cant make it work with a gyro...... anyone know why? doset observe the comparison.

Code: [Select]


#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);
float sensornow;
float sensorlast;
long timer = 0;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);
  Serial.println();
  Serial.println(" READY ");}

void loop() {
  if(millis() - timer > 0){
  mpu6050.update();
  if (mpu6050.getAngleX() < -10){
        sensornow = (mpu6050.getAngleX());
        sensorlast = sensornow;                             // update sensorlast variable
    if (sensornow > sensorlast) {                           // did direction change? then....
    Serial.print ("Run stepper XX Steps Left cw ");
    Serial.println (sensorlast);}}

  if (mpu6050.getAngleX() > 10){
        sensornow = (mpu6050.getAngleX());
        sensorlast = sensornow;                             // update sensorlast variable
    if (sensornow < sensorlast) {                           // did direction change? then;
    Serial.print ("Run stepper XX Steps Right ccw ");
    Serial.println (sensorlast);}}
    Serial.println(sensorlast);
 
    timer = millis();  }}
Pages: [1] 2 3 ... 10