I am new to Arduino, and I have an ethernet shield with an SD socket on top, but it not seems to be working.
I am just trying to run a simple sketch taken from the SD libraries example to get infos about the card, but the "card.init(SPI_HALF_SPEED, chipSelect)" part always fails.
I have set the ChipSelect pin to 4, and set pin 10 to output, still nothing.
My code:
#include <SD.h>
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("\nInitializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT); // change this to 53 on a mega
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
}
void loop(void) {
}
What I get:
Initializing SD card...initialization failed. Things to check:
* is a card is inserted?
* Is your wiring correct?
* did you change the chipSelect pin to match your shield or module?
I am using Arduino Uno R3, Ethernet Shield (not the official one).
I have tried with several SD cards: SD/SDHC, 2/4/16 Gb, Sandisk/Kingston, formatted with FAT16/FAT32
I am afraid something is bad with the shield itself (though the ethernet part is working). How can I identify the source of the problem? Please Help!
Check here:
https://electronics.stackexchange.com/questions/67212/how-to-avoid-sd-card-and-w1500-spi-mixup-on-the-ethernet-shield/93868#93868
short overview of the answer from the link above:
#define SS_SD_CARD 4
#define SS_ETHERNET 10
digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
digitalWrite(SS_ETHERNET, HIGH); // Ethernet not active
digitalWrite(SS_SD_CARD, LOW); // SD Card ACTIVE
//do SD-Card stuff here
digitalWrite(SS_SD_CARD, HIGH); // SD Card not active
digitalWrite(SS_ETHERNET, LOW); // Ethernet ACTIVE
//do Ethernet stuff here
if you have a Arduino Ethernet / SD Shield with the Wiznet 5100 Chip on it, you have exactly that known W5100 bug - as my Shield has. There are more informations about that bug by googling it.
When you connect this shield with the arduino the ethernet function is active and will not work if a sd-card is inserted in the slot. By using one of the Ethernet Examples from the standard library you will always get a DHCP failure (Failed to configure Ethernet using DHCP). By removing the SD-Card and restarting arduino (reset) it will work.
When you have to use both functions as I like to do you will have to struggle within the code in order to turn ethernet off and sd on and vice versa.
pinMode(4, OUTPUT);
or to be correct
pinMode(chipSelect,OUTPUT);
Add this in the setting pin 10. hope this helps.
Some times in life it is the little things that mess us up.
Put the following line of code after you set the pin 10 to output:
digitalWrite(10, High);
This should do the trick.
FYI for anyone experiencing similar issues, i.e. using the Ethernet shield SD card and essentially the Arduino website SD card sample code and having inexplicable issues initializing the SD card. The above solution allowed the initialization for me.
I ran your code and fixed it by initializing SD.begin() before the line Serial.print("\n Initializing SD card...");
Something like this:
SD.begin();
Serial.print("\nInitializing SD card...");
Related
I can't see any Serial.print() outputs in Visual Studio Code from my Arduino device (an ESP8266 in this case). I was expecting to see it on the Debug Console. Do I have something configured incorrectly?
I know my code is working as the LED is flashing but I'm not seeing any output anywhere.
Here's my code:
#include <Arduino.h>
void setup()
{
Serial.begin(9600); // EDIT: added this line
Serial.println("Setup...");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
Serial.print("On!");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
Serial.print("Off!");
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
I am using this board:
https://www.waveshare.com/wiki/e-Paper_ESP8266_Driver_Board
Here is my platformio.ini file:
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
; Custom Serial Monitor port
monitor_port = COM4
; Custom Serial Monitor speed (baud rate)
monitor_speed = 9600
Near the bottom right of the VS Code screen is a little plug icon. Click that to open the serial monitor.
Set serial port baud rate in setup() by adding this code:
Serial.begin(SERIAL_BAUD_RATE);
For example:
Serial.begin(9600);
Finaly in serial port monitor set baud rate
I want to drive an actuator from 5 volt Arduino pro mini and it's control by Bluetooth signal from mobile .
circuit detail:
1)Arduino Promini 5 volt
2) Hc05 Bluetooth Module
3)5volt Actuator
I was powering 11.8 Volt directly to the RAW pin of Arduino pro mini .
When It was receiving 1 or 0 it is unable to control the actuator and after connecting the data pin of actuator with pin 13 of arduino pro-mini the flash light continuously blinking
But Above same operation perfectly done by Arduino Uno Board. So is there any possible to control the actuator using arduino promini over bluetooth signal. Reason behind I am using Arduino pro mini instead of Arduino Uno it's took less space.
Arduino Code:
#include<SoftwareSerial.h>
SoftwareSerial BT(2, 3);
#include <Servo.h>
Servo myservo;
int ServoPin =13;
void setup()
{
Serial.begin(9600);
myservo.attach(ServoPin);
pinMode(ServoPin, OUTPUT);
digitalWrite(ServoPin, LOW);
myservo.write(40);
// set digital pin to control as an output
pinMode(9, OUTPUT);
// set the data rate for the SoftwareSerial port
BT.begin(9600);
// Send test message to other device
BT.println("Hello from Arduino");
}
char a; // stores incoming character from other device
void loop()
{
if (BT.available())// if text arrived in from BT serial...
{
a=(BT.read());
Serial.println(a);
if (a=='1')
{
digitalWrite(9, HIGH);
BT.println(" You have to turn oN the LED/servo| I got the command : 1 ") ;
Serial.println("I got the command :");
Serial .println(a);
myservo.write(180);
a=' ';
}
else if (a=='0')
{
myservo.write(40);
digitalWrite(9, LOW);
BT.println(" You have to turn Off the LED!/servo| I got the command :0");
Serial.println("I got the command :");
Serial .println(a);
a=' ';
}
}
}
i think the issue is with the current. first check how much power is required to drive the actuator. if the current is insufficient you can use ULN2003 it's a relay driver ic but you can use it for your ckt if you are less in space you can use single darlington pair.
I'm working on a project that need to shutdown arduino main power (not sleep) to save battery.
Follow this tutorial:
zola lab
Here is Zola scheme (i choose the relay option):
And here what i have done:
The code:
// www.zolalab.com.br - By Eduardo Zola - 2016
void setup()
{
pinMode(7,OUTPUT); // Relay Signal Pin
digitalWrite(7,HIGH);
pinMode(8,OUTPUT); // buzzer & LED (start with buzzer on)
digitalWrite(8,HIGH);
pinMode(13,OUTPUT); // LED built-in Arduino
digitalWrite(13,HIGH);
delay(50);
digitalWrite(8,LOW); // turn off buzzer
delay(5000); // wait for 5 seconds to shutdown the circuit
for(int i = 0;i<3;i++){
digitalWrite(8,HIGH);delay(80);digitalWrite(8,LOW);delay(600);
}; // beeps
digitalWrite(8,HIGH);delay(1000);digitalWrite(8,LOW);
digitalWrite(7,LOW); // shutdown the circuit
}
void loop()
{
}
My main power 5v in breadboard come at the top left.
The relay is different. My relay is this:
Problem is, when i click switch button in the breadboard, nothing happened.
Any help would be very appreciated.
The breadboards like yours usually have power rails separated in the middle. On a photo of your setup it looks like you connected your power supply to the upper half of the board, and reset of the circuit to the lower. Try connecting everything on the same half, or use jumpers to connect power rails.
Found the solution.
Change the digitalWrite from HIGH to LOW and LOW to HIGH for pin 7
void setup()
{
pinMode(7,OUTPUT); // Relay Signal Pin
digitalWrite(7,LOW); // <-- change this
...
...
digitalWrite(7,HIGH); // shutdown the circuit <-- change this too
}
void loop()
{
}
Hope this help others for having same relay.
Before you mark this question as duplicate, please note that I have already tried this, this & this
I bought an Arduino UNO R3 & a SIM808 GSM/GPS shield recently. The RX of the Shield is connected to Pin 11 of Arduino, TX to Pin 10 with both the GNDs connected to each other. I have connected my Arduino to my computer with the USB & the shield is connected to an external power supply with a 12V Adapter. Additionally, I have connected the 3.3V of the Arduino to Vcc of the shield.
Following is the sketch I have used:
// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
}
void loop() {
Serial.print("Enter a mobile number: ");
char remoteNum[20]; // telephone number to send sms
readSerial(remoteNum);
Serial.println(remoteNum);
// sms text
Serial.print("Now, enter SMS content: ");
char txtMsg[200];
readSerial(txtMsg);
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);
// send the message
sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}
/*
Read input serial
*/
int readSerial(char result[]) {
int i = 0;
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n') {
result[i] = '\0';
Serial.flush();
return 0;
}
if (inChar != '\r') {
result[i] = inChar;
i++;
}
}
}
}
Problem here is same as that mentioned in those linked posts.
The condition if (gsmAccess.begin(PINNUMBER) == GSM_READY) never gets executed. Neither does the else part execute.
Serial monitor never goes past SMS Messages Sender.
Please note that I am using AirTel India, I have a fully activated Data Plan & the PIN Number has been changed to 0000.
Would really appreciate if someone could suggest something helpful.
Thanks for your time!!
You cannot power a GSM module from the 3.3V of Arduino! a GSM needs peak currents of 3A (yes, Amps, not milli-amperes). You really need a LiPo battery to power the GSM. You could power a 3V Arduino from the same LiPo battery, actually, if you need a mobile solution, but not the other way around.
Please first check if the module responds with the next code Example Code
Other thing the Supply voltage range must be 3.4 ~ 4.4V, try not using less voltage .
The GSM library of the Arduino is for the Quectel M10 GSM/GPRS module and is not compatible with SimCom SIMxxx modules.
Here is the library that you can use for your SIM808 module https://github.com/MarcoMartines/GSM-GPRS-GPS-Shield (examples included in the repo). Note that this library uses the SIM900 library which allows low level interface with SimCom modules.
For further reading here two adafruit links:
http://wiki.iteadstudio.com/SIM808_GSM/GPRS/GPS_Module
https://www.adafruit.com/products/2637
the shield is connected to an external power supply with a 12V
Adapter. Additionally, I have connected the 3.3V of the Arduino to Vcc
of the shield.
What do you mean by that? You need to supply your shield with the required voltage that can deliver the required amps. And also you need to have a common ground with your arduino.
In addition, if your shield is a 3.3V you need to shift Tx line comming from arduino as well (because it's a 5V) using a voltage divider.
Note that these shields have also a soft power-up button that needs to be connected as well, to allow the code to power up your module.
Is it possible to communicate between two ATtiny85? I can use my Arduino to communicate with ATtiny85 by using Arduino Uno as the master and ATtiny85 as a slave. But I want to use one ATtiny85 as the master and one as a slave. Is this possible ?
I am not able to understand the examples given in TinyWireM library. I want a simple master and slave code for communication. For example, master should ask for 1 integer value and slave should reply.
My slave code :
#define I2C_SLAVE_ADDRESS 0x14 // Address of the slave
#include <TinyWireS.h>
int i=0;
void setup()
{
TinyWireS.begin(I2C_SLAVE_ADDRESS); // join i2c network
TinyWireS.onRequest(requestEvent);
}
void loop()
{
TinyWireS_stop_check();
}
void requestEvent()
{
if(i==1000)
{
TinyWireS.send(1);
i=0;
}
else
i++;
}
My master code
#include <TinyWireM.h>
#define DS1621_ADDR 0x14
void setup()
{
TinyWireM.begin();
pinMode(4, OUTPUT);
}
void loop()
{
TinyWireM.requestFrom(DS1621_ADDR,4); // Request 1 byte from slave
int tempC = TinyWireM.receive();
if(tempC)
{
digitalWrite(4, HIGH);
delay(1000); // wait for a second
digitalWrite(4, LOW);
delay(1000); // wait for a second
}
if(tempC>1)
{
digitalWrite(4, HIGH);
delay(1000); // wait for a second
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
I tried the above code but still I cannot see the LED blinking. But if I keep slave code as it is and use the following master code on an Arduino then everything works fine.
Arduino Uno code as master.
#include <Wire.h>
float i1=-1, i2=-1;
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(4, 1); // request 1 byte from slave address 4
while(Wire.available()) // slave may send less than requested
{
i1 = Wire.read(); // receive a byte as character
Serial.println(i1); // print the character
}
}
connection is and connections are SDA to SCL pins
pin 5 of master attiny85 - pin 7 of slave attiny85
pin 7 of slave attiny85 - pin 5 of master attiny85
I also tried by no cross connecting them. example and connections are SDA to SDA pins
pin 5 of master attiny85 - pin 5 of slave attiny85
pin 7 of slave attiny85 - pin 7 of master attiny85
but still no success.
Yes, it is possible to use 1 ATtiny85 as a master, and another as a slave. The TinyWireM and TinyWireS libraries are both well-written and easy to use.
Handling a request and sending back bytes is as simple as setting the onRequest slave read event handler to a function of your choice that sends the correct data back. There are examples of this in the TinyWireS library.
Did you use the pull-up resistor for both, the SDA and SCL? They are important for the I2C protocol.
FYI: The logic '0' on the either bus is set by device driving actual '0' on the pin. On the other hand, the logic '1' is set on the bus by putting the device pin in the high impedance, in case on the ATtiny, it means setting pin into INPUT direction. When the both, the master and slave set pins to hiZ, the pull-up resistor pulls the voltage on the bus to value representing logic '1'. This solution allows avoiding contention on bi-directional bus (one device driving '1' and second driving '0') than can lead to short-circuit and damaging devices. So, if you don't use the pull-up resistor, the bus will be left floating whenever logic '1' is driven and it will lead to protocol errors.