Particle Photon, controlling a PCF8574 via I2C- works on Arduino - arduino

I'm trying to read and control some buttons and LEDs on a Bang & Olufsen infrared eye. It uses a pcf8574 microcontroller to control 2 LEDs and 4 buttons. First of all I just want to get the LEDs to blink. I have successfully done that with an Arduino Uno.
But I want to use it with an Particle Photon so I can connected to the internet. Here I have the code that worked on the Arduino:
#include <Wire.h>
#define beolink (B0100000)
void setup() {
Wire.begin();
}
void loop() {
Wire.beginTransmission(beolink);
Wire.write(0b11111111);
Wire.endTransmission();
delay(1000);
Wire.beginTransmission(beolink);
Wire.write(0b00111111);
Wire.endTransmission();
delay(1000);
}
I have no errors on the Particle Photon. I have also tried switching cables and tried 5v instead of the 3.3v. I have connected the pins on the Particle Photon to the same as on the Arduino [SCL(D1) & SDA(D0)].

Thanks to this guy: https://community.particle.io/u/scruffr/summary
It now works. It was not a problem with the code. Apparently you need 2 pull-up resistors on the I2C pins on a Particle Photon. thank you

Related

Motor shield not moving as expected

Motor shield is not working as expected when connected to battery. When Arduino is connected to USB, motor is moving both FORWARD and BACKWARD, but when connected to battery, it moving only in FORWARD direction. I don't think so it's battery issue, because motor speed is good even it moves only in FORWARD direction.
Below is the code,
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
void setup() {
Serial.begin(9600);
Serial.println("Motor");
motor1.setSpeed(254);
motor2.setSpeed(254);
motor1.run(RELEASE);
motor2.run(RELEASE);
}
void loop() {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
delay(500);
motor1.run(FORWARD);
motor2.run(FORWARD);
delay(500);
}
Well, it should work with your above code. But note that there is a jumper on the shield that you have to remove in order to power it through the battery.
Requires a little power trigger or if we wait for around 2-3 minutes the motor works good. Motor shield drains the battery often. Seems to be it requires more power supply. Power supply from USB cable works perfectly rather than batteries

Conneting Adafruit m0 with dht22

I am new to low-level programming, and attempting to connect a DHT22 sensor onto my Adafruit M0 Lora for temperature readings. So far I only retrieve NaNs.
The connections I have set up are identical with this sketch, aside from using pin 13 as opposed to pin 2 for sensor input/output. I am aware of the sketch being made for a different feather board, although the logic should still remain the same from what I can understand.
I am making use of Adafruit's DHT library
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
// pin connected to DH22 data line
#define DATA_PIN 13
DHT_Unified dht(DATA_PIN, DHT22);
void setup() {
// start the serial connection
Serial.begin(9600);
// wait for serial monitor to open
while(! Serial);
// initialize dht22
dht.begin();
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
// we are connected
Serial.println();
}
void loop() {
sensors_event_t event;
dht.temperature().getEvent(&event);
float celsius = event.temperature;
float fahrenheit = (celsius * 1.8) + 32;
Serial.print("celsius: ");
Serial.print(celsius);
Serial.println("C");
Serial.print("fahrenheit: ");
Serial.print(fahrenheit);
Serial.println("F");
// save fahrenheit (or celsius) to Adafruit IO
dht.humidity().getEvent(&event);
Serial.print("humidity: ");
Serial.print(event.relative_humidity);
Serial.println("%");
delay(5000);
}
Would anyone be able to help point of what I am doing incorrectly? I tried at other bauds than 9600, as well as changing the programmable pin. Any help at all would be greatly appreciated.
I don't think it's a code problem. Pin 13 is special. Choose a different pin.
Specifically:
NOTE: Digital pin 13 is harder to use as a digital input than the other digital pins because it has an LED and resistor attached to it that's soldered to the board on most boards. If you enable its internal 20k pull-up resistor, it will hang at around 1.7V instead of the expected 5V because the onboard LED and series resistor pull the voltage level down, meaning it always returns LOW. If you must use pin 13 as a digital input, set its pinMode() to INPUT and use an external pull down resistor.
From Arduino documentation.

Arduino LED not blinking

I am a beginner to ARDUINO. My connections i guess is fine. But LED does not blink. Green and Orange light is blinking on ARDUINO. Anode to pin 13 with 320K resistor and Cathode to ground
Code is as follows
const int LED=13;
void setup()
{
// put your setup code here, to run once:
pinMode(LED,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
delay(1000);
}
Looks like you plugged one of the legs in ground and one in Another slot.
Check your connections and if it doesn't work, try using another led, and switching the polarities.
The problem here in that you haven't connected anything to pin 13!
Also, a 320K ohm resistor is a little overkill. Usualy, a 220 ohm resistor is enough.
Also, the flat side of the led is the negative side. It is more reliable then if you are following the pins size which isn't always constant.
You need a resistor even if using pin13.
The led in the shield has it's own resistor but if you plug your own you need a resistor.
Take a look at this post:
https://electronics.stackexchange.com/questions/66992/pin-13-do-i-need-a-resistor
hello you can try removing the 320K resistor and replacing it with 220 ohms resistor or directly connec t LED to pin 13 because the onboard resistor is on

Arduino Uno DC Motor not working with simple test. Can not get Arduino to spin the motor

I am using the V2.3 motorsheild on the arduino uno r3.
I no almost nothing about ardunio excpet from what ive read about the past week.
I have been trying to simply turn the motor with the code below and it wont work. I have the arduino plugged into my computer and 12v going to the blue power box thing.
I am using this motor https://www.servocity.com/html/900_rpm_micro_gearmotorblocks.html#.VyELIFaDFBc
I cannot get the dang thing to spin, motor works fine if i wire it straight to the 5v/grnd but not when its in the M1 connection
wiring: https://i.groupme.com/747x1328.png.54a01e30433241d4a99905bd0e8ede2b let meknow if this link doesnt work
Heres an Imgur link for the wiring http://imgur.com/J92ewnu
#include
AF_DCMotor motor(1);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
// turn on motor
motor.setSpeed(200);
motor.run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
motor.run(FORWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
motor.setSpeed(i);
delay(10);
}
Serial.print("tock");
motor.run(BACKWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
motor.setSpeed(i);
delay(10);
}
Serial.print("tech");
motor.run(RELEASE);
delay(1000);
}
I am not expert in current particular shield and its library. But what i see when first time look at your sketch and motor connection image is that you are trying to run dc motor at a certain speed with commands, which seems to be for servo or stepper motors.
You should know that running DC motor at some speed is possible if you have speed calculation based on its current and voltage or when a speed sensor is located at motor's shaft. This motor doesn't have the sensor (i know it for sure, because used same in my projects) and i think the shield can't calculate speed. What you can is only switch it on and off and maybe change its direction.
So, first of all you should look (and use) at the library for such functions.
Looking for what the function you called "AF_DCMotor" does I see how you were confused. There is also this product, which is another adafruit motor sheild.
But it's actually a very different motor driver. Both shields have a power stage which takes pulses and amplifies them to drive a motor. The V2 apparently has a chip which generates these pulses, and you send it serial data to command it using I2C. The V1 just gets these pulses directly from the Arduino.
For yours, a V2 motor shield, try the guide Adafruit provides.
Here's the link - Adafruit Motor Sheild V2 DC motor control
And here's the code
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
AFMS.begin();
myMotor->setSpeed(100);
myMotor->run(FORWARD);
It mentions the use of I2C on the introductory page
Instead of using a latch and the Arduino's PWM pins, we have a fully-dedicated PWM driver chip onboard. This chip handles all the motor and speed controls over I2C
That's why it includes the Wire library. You could make your own code to run this, but it would have to use I2C to send commands to the PWM driver chip they are using.

Arduino 16x2 LCD Stays Blank

I am using an Arduino Mega with a 16x2 LCD. When I start the Arduino the LCD flashes white and sometimes random lines will show up and gradually fade out. The backlight is on, however, so the LCD is not inverted. At first I thought the Arduino was not getting enough power because I am using a Raspberry Pi to program it, but plugging in a 6V battery pack did not change the result. I tried plugging in a different 16x2 LCD to check if the one I was using is broken, but again, the result was the same. I have triple-checked my connections, adjusted the potentiometer, and fiddled around with where the LCD was connected on the breadboard in case some of the pins were broken, but to no avail.
Does the LCD have a problem with Arduino Mega boards? Or am I just unfortunate enough to have two broken LCDs?
Code:
#include <LiquidCrystal.h>
#define led_pin 22
#define buzzer_pin 7
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(buzzer_pin, OUTPUT);
lcd.begin(16,2);
digitalWrite(led_pin, HIGH);
tone(buzzer_pin, 1000, 500);
delay(500);
digitalWrite(led_pin, LOW);
lcd.print("LCD Test");
}
void loop() {
}
EDIT
I moved the LCD and wiring back to the other side of the breadboard and it did not change the output. I'm starting the think that the LCDs are just simply broken because the LCDs will randomly flash and fade unevenly. I found that these LCDs can be easily fried by incorrectly adjusting the potentiometer.
Make sure that you solder headers to the lcd, then press the headers into your breadboard and connect to arduino with jumper wires. Just resting the LCD on the headers without solder or jabbing the lcd pin holes with jumper wires don't make reliable connections. You WILL see random stuff
Make sure you connect the LCD correctly. If you did, you wouldn't have got any problems. Post a picture.
Make sure the pins you used in the code match pins you connected to the LCD.
Best way to get arduino help is on arduino forum.
Specifically which LCD are you using?
Do you have datasheets for the exact LCD you are using so you can confirm you have the correct wiring and supply voltages?
If you still have no luck, you may want to try a LCD module that has a serial, i2c, or spi interface.
They are much easier to use than HD44780 parallel modules (im assuming this is what you have).
An example source of such modules is https://www.crystalfontz.com/c/character-lcd-displays/interface/24

Resources