I am using Arduino Nano with HX711 scales module and cc2541 Bluetooth module(Bluetooth 4.0) to send data to Android device.
#define RX 11
#define TX 10
#include "HX711.h"
HX711 scale(A1, A0);
float scale_calibration = -13.5;
float mass,massround;
float units;
int out;
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(TX, RX);
void setup()
{
bluetooth.begin(9600);
scale.set_scale();
scale.tare();
scale.set_scale(scale_calibration);
}
void loop()
{
for(int i = 0;i < 10; i ++) units =+ scale.get_units(), 1;
units / 10;
mass = units * 0.035274;
massround=mass;
out = round(massround);
out = abs(out);
if(out<0)
{
out=0;
scale.tare();
}
bluetooth.println(out);
}
If I run Arduino using USB coonected to my PC, the scales work perfect and give right results via Bluetooth. However, when I run Arduino using battery (not connected to PC), I get 0-3 grams value, while there is nothing on the scales. So because of that all measurements are incorrect. How can I fix this problem?
When your Arduino is powered from USB, it and the HX711 probably have both VCC and VDD at +5 volts, making the 'reference' voltage (VDD) 5 volts.
When running off battery, the hardware is receiving ~3 volts, and if VCC and VDD are shorted together on the HX711, it might 'kinda work' but would give spurious results.
There's probably jumpers or bridges to set VCC and VDD on both the arduino and the load cell. CAUTION! I'm just guessing here, and be sure to read the tech docs before changing the voltage settings, it's easy to cook these little circuits with a minor change in voltages.
This might be better asked in a hardware or electrical engineering channel.
Related
Arduino MEGA 2560: I want an interrupt to execute when a button push occurs on a rotary encoder. I have the code working. However, if I add a function call to Adafruit's FT6206 library the MEGA 2560 hangs. (Evidence of this is that the Serial.println command text is cut-off mid stream of display.) Why?
Hardware setup: rotary encoder push button has two pins: one side is connected to the interrupt pin with a pull-up for power, and the other side tied to ground.
No other hardware or shield is connected. The hardware set up is only the rotary encoder wired to the MEGA 2560 to demonstrate the issue in its simplest form; however, I have the same issue when the TFT display shield is installed.
The MEGA 2560 is the INLAND brand. The rotary encoder is from Adafruit.
Here is the code:
#include "Adafruit_FT6206.h"
// Global Variables
const byte RotarybuttonPin = 21;
volatile byte Rotarybutton_Pressed_Flag;
TS_Point touchpoint;
Adafruit_FT6206 ctp = Adafruit_FT6206();
void setup() {
ctp.begin(70);
Serial.begin(115200);
pinMode(RotarybuttonPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(RotarybuttonPin), Button_Pin_ISR, LOW);
}
void Button_Pin_ISR() {Rotarybutton_Pressed_Flag = 1;}
void loop() {
Serial.println("In Loop!");
touchpoint = WAIT_FOR_SCREEN_TOUCH();
}
TS_Point WAIT_FOR_SCREEN_TOUCH() {
CHECK_ROTARY_ENCODER();
Serial.println("Entering 'While'");
//This next line locks the MEGA 2560 up with ctp function call
while (!ctp.touched()) {CHECK_ROTARY_ENCODER();}
return (touchpoint);
}
void CHECK_ROTARY_ENCODER() {
if (Rotarybutton_Pressed_Flag) {
Serial.println("PRESSED");
Rotarybutton_Pressed_Flag = 0;
}
else {Serial.println("NOT PRESSED");}
delay(190);
}
Discovered the issue and wanted to share the solution with the community.
The MEGA2560 has six interrupt pins: 2, 3, 18, 19, 20, 21. However, when using the FT6205 which is part of Adafruit's 2.8" TFT shield, the interrupt pins 20 and 21 become unavailable as they are being used by the I2C bus. Interrupts are limited to pins 2, 3, 18, and 19.
This limitation is a bit problematic as the TFT shield blocks easy access to pins 2 and 3. However, it is possible to share a header pin with the shield with a #22 gauge wire.
Pins 18 and 19 are not blocked by the TFT shield and could be used. However, I want to use these pins for their interrupts in detecting clockwise and counterclockwise rotary encoder movement.
I recently got an Arduino Uno Wifi (flashed it with the Wifilink firmware to support UDP) and I have created a simple sketch to read analog values from a flex sensor.
I am using the code below (copy paste from the official website)
const int FLEX_PIN = A4; // Pin connected to voltage divider output
// Measure the voltage at 5V and the actual resistance of your
// 47k resistor, and enter them below:
const float VCC = 4.98; // Measured voltage of Ardunio 5V line
const float R_DIV = 47500.0; // Measured resistance of 3.3k resistor
// Upload the code, then try to adjust these values to more
// accurately calculate bend degree.
const float STRAIGHT_RESISTANCE = 37300.0; // resistance when straight
const float BEND_RESISTANCE = 90000.0; // resistance at 90 deg
void setup() {
Serial.begin(9600);
pinMode(FLEX_PIN, INPUT);
}
void loop() {
// Read the ADC, and calculate voltage and resistance from it
int flexADC = analogRead(FLEX_PIN);
float flexV = flexADC * VCC / 1023.0;
float flexR = R_DIV * (VCC / flexV - 1.0);
Serial.println("Resistance: " + String(flexR) + " ohms");
// Use the calculated resistance to estimate the sensor's
// bend angle:
float angle = map(flexR, STRAIGHT_RESISTANCE, BEND_RESISTANCE, 0, 90.0);
Serial.println("Bend: " + String(angle) + " degrees");
Serial.println();
delay(500);
}
The code does not work in the Arduino Uno Wifi: it does not show any change in the bend degrees. However, it works in another Arduino Uno I have for testing.
Also I made a test and I found out that pins 4 and 5 in Arduino Uno Wifi produce current for some reason even with an empty script, capable of lighting a LED (while pins 0,1,2,3 do not light it up).
The same applies for the values for the sensors. For example if I put the flex sensor in analog pin 0 then the values change when I bend it (e.g. 362 read not bend and 600 bend, which is fine).
On the other hand when I put the pin of the sensor in A4 or A5 there is a change from 1023 (starting value) to 982 and it won't change no matter if I bend the sensor.
I was recently informed that those pins are Wire/TWI/I2C pins. Is there any way i can read analog input from those pins?
Also posted in Arduino forums link
'WiFi' is connected to those pins.
pins A4 and A5 are Wire/TWI/I2C pins and there is the additional UART SC16IS750 connected to which the esp8266 is connected on Uno WiFi
I have a problem with flickering neopixel leds. I'm using a setup of 6 strips of 8xWS2812 5050 leds. I've connected these to a 5v power supply (USB charger) and an Arduino Uno running the Neopixel simple example code:
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 48
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 50; // delay for half a second
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
for(int i=0;i<NUMPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(200,200,200)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
I've connected a 500uf 10v capacitor between the 5v and the gnd. And a 470 ohm resister between the arduino and the datapin.
I've noticed that the leds also flicker when the leds are on and the datapin is disconnected. The flickering is subtle, but annoying.
I've also tried an alternative power supply. For this I used a adjustable lab power supply. But the same problem persists.
I have to use these leds for a project that I need to finish tomorrow. (I know i should have done this earlier) Is there anyone who could offer me some help? I could really use some.
EDIT: The flickering had to do with the quality of the leds. These weren't real neopixels, instead I received some bad fake ones.
I am trying to attach a servo on an Arduino (branded) Robot but not sure whhich pin to use for the bellow code.
Most people seem to recommend to use pin 9 and 10 to control the servo for arduino Unos.
However, I can't use Pin 9 because that is already used as the Slave Select pin for the LCD.
I have tried attaching it to pins TKD0-TKD3 by calling them pins 19-22 in myservo.attach(). The code runs but the servo doesn't rotate and only gets hot and/or twitches.
Could the problem be something other than incorrect pin connection?
Thanks,
-M
I have been referencing these for the Control board pin mapping:
http://arduino.cc/en/Main/Robot)
http://fabcirablog.weebly.com/blog/grappling-with-the-arduino-robot-control-board
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0;
void setup()
{
myservo.attach(19); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 60; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 60; pos>=1; pos-=1)
{
myservo.write(pos);
delay(15);
}
}
You have this robot, right?
Arduino Robot
And you are using a classic servo (3 pins, yellow red and black cable)? If so.... Watch out. According to the schematic, the pinout of the connector on the board (e.g. TKD0) is
+5V
AD1
GND
While usually servos have
DATA
+5V
GND
So.. you have to make a short cable to invert the pins.
If that's not the problem.. Are you sure that 19 is the right number for the pin? I can't find references, but i suggest you to call it TKD0 (which is probably a macro defining the right pin), as arduino designers suggest you.
So my problem is as title says: Arduino UNO analogRead always returns 1023.
But when I burn the same sketch in Arduino Mega 2650 everything works like a charm.
I have tried to change Atmel chips on the UNO, have tried like 3 of them (ATMEGA328P-PU) and nothing changes.
I'm trying to count signals from a hall effect sensor and display the count on a 7 segment display.
Here is the code:
#include "SevSeg.h"
SevSeg sevseg;
volatile int rpmcount;
void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
rpmcount = 0;
sevseg.Begin(1,3,4,5,6,7,8,9,10,11,12,13);
}
int border=15;
void loop() {
int tmp=0;
tmp = analogRead(0);
if(!digitalRead(2))rpmcount=0;
Serial.println(tmp,DEC);
if(tmp<=border && res >border){
rpmcount++;
if(rpmcount>9999)rpmcount=0;
}
res=tmp;
sevseg.NewNum(rpmcount,(byte) 0);
sevseg.PrintOutput();
}
Any help would be much appreciated
This sounds to me as if you had the internal pullup resistor on the ADC pin enabled.
generic checklist:
ACD bit in ACSR is 0 (comparator enable)
MUX bits in ADMUX set properly
correct AREF selected
ADC pin set as input
internal pull up resistors are deselected