RFID does not respond after Ethernet.begin(mac, ip) initialization - arduino

Good day, I have this problem with my simple project. I have a database with all RFID number of employee. What I want to do is to use an rfID to check if it is registered in the database. If it is, it would return a value of 1 else would be a value of 0.
I tried with arduino HanRun Ethernet shield. I was able to get a response from the php web server to the serial monitor. Tried the seeedrfid it successfully get the rfcard number. However, when i tried to combine the two, it would hang on Ethernet.begin(mac, ip) initialization. My code is below.
#include <Ethernet.h>
#include <SoftwareSerial.h>
#include <SeeedRFID.h>
#define RFID_RX_PIN 10
#define RFID_TX_PIN 11
SeeedRFID RFID(RFID_RX_PIN, RFID_TX_PIN);
char state = '0';
char c;
byte mac[] = {0x60, 0xF8, 0x1D, 0xBA, 0x1D, 0x52};
IPAddress ip(192, 168, 20, 228);
EthernetClient client;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Serial set up");
Ethernet.begin(mac, ip);
Serial.print("My IP Address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
long rfID;
// put your main code here, to run repeatedly:
if (RFID.isAvailable()) {
rfID = RFID.cardNumber();
Serial.println(rfID);
}
}
Serial.println(rfID) is not executed unless I remove the Ethernet.begin(mac, ip). Can anybody point me to the right direction?
Thank you everyone for helping out. My supervisor who gave me the shield just remembered that there might be a pin changes(or anything you call it). That I might need to try other pin in order for the rf reader and ethernet shield to work together. now its working fine..

Related

How to send analog data of NodeMCU wirelessly to labview for post processing in labview?

I want to send my microphone data wirelessly to labview and then I want to do some post processing over that data like FFT, amplification and stuffs like that.
How should I proceed exactly?
I have researched a lot about this but didn't find any sufficient answer to this.
I have setup my microcontroller and the microphone module and i am able to get values on the serial monitor.
I have also connected my nodemcu to my AP and thought to use esp8266 as a web-server so that I can send the data to labview but cant possibly do it.
This is my current code:
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
int val=0;
ESP8266WebServer server(80);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
const char* id = "****";
const char* pass = "****";
WiFi.begin(id,pass);
while(WiFi.status()!=WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.print("Connected successfully to: ");
Serial.println(id);
Serial.print("The IP address is: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop() {
// put your main code here, to run repeatedly:
server.handleClient();
int val= analogRead(0);
Serial.println(val);
server.send(200,"text/html",String(val));
}

code don't work on my d18b20 temperature sensor

The simple code for arduino is down the page and everything works (it shows me temperature as it is), but in this example I include ethernet and begin internet and it doesn't show me temperature anymore....in serial monitor it just shows me temperature -127.00, so it mean it doesn't work. I am very new at programming, so I am sorta noob and maybe it's some banal question and answer, but I don't get it, why I cant start ethernet in setup function. I only need that for my other project which will include mqtt, so I will need ethernet. Please help and thanks for answers.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Ethernet.h>
// Data wire is plugged into pin 12 on the Arduino
#define ONE_WIRE_BUS 12
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 80);
void setup(void)
{
Serial.begin(9600); //Begin serial communication
Ethernet.begin(mac, ip);
Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
sensors.begin();
}
void loop(void)
{
// Send the command to get temperatures
sensors.requestTemperatures();
Serial.print("Temperature is: ");
Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Update value every 1 sec.
delay(1000);
}

Arduino Ethernet Shield Not Assigning Correct IP Address

I've purchased two of the Arduino Ethernet Shields made by Arduino. I am using the Arduino Uno for my project. I cannot seem to assign an IP address to the shield. When I run the following code I receive 0.253.253.253 as the IP for one of the shields, and for the other one I receive 0.15.15.15 with the exact same code. I have no Idea what's going on here. Any help would be appreciated. Thanks
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x30, 0x71 };
IPAddress ip(192,168,1,22);
void setup() {
Serial.begin(9600);
// disable SD card if one in the slot
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
delay(5000);
Serial.println("Starting w5100");
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
}
void loop() {
}
If both the boards are connected on the same network then they can't have the same IP address, change the address of one of the boards.
edit :
Check if it is indeed starting up properly
if(!Ethernet.begin(mac, ip))
Serial.println("failed");
else
Serial.println(Ethernet.localIp());
Also try it without the ip, to check if your router can assign the ip address.

Arduino Ethernet Shield 2 not working

I am currently trying to get the Ethernet Shield working on my Mega. I was trying to run the Webserver example but the program seems to stuck at one point, so I tried to start from scratch.
This is my test code:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0F, 0xF6, 0x3D
};
byte subnet[] = { 255,0,0,0 };
byte gateway[] = { 2,0,0,1 };
IPAddress ip(2, 0, 0, 1);
EthernetServer server(80);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway, subnet);
Serial.println("Ethernet started");
server.begin();
Serial.println("Server started");
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Loop");
}
The output I get from the serial console is:
Etrted
Ethernet started
So I think the program gets stuck inside the EthernetServer::begin() function.
I am aware that there are earlier versions of ethernet shields which are not compatible to the mega, but the vendor of my shield says it is.
Also I don't understand, why it outputs the first line.
Thanks for your hints!
Arduino.cc and Arduino.org are not the same... Arduino.org, who is selling the ethernet shield 2, has their own IDE with the correct library! You can download it at http://www.arduino.org/downloads and the source can be found at https://github.com/arduino-org/Arduino/tree/1.7.4/libraries
Try this code form (http://www.arduino.cc/en/Tutorial/DhcpAddressPrinter):
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop() {
}
And post what the serial monitor output is.
Try this:
NB. You can reuse your code written for Arduino Ethernet Shield, simply replacing
#include <Ethernet.h> --> #include <Ethernet2.h>
#include <EthernetUdp.h> --> #include <EthernetUdp2.h>
See this: http://labs.arduino.org/Arduino+Ethernet+Shield+2

My Arduino + Ethernet shield WebServer sketch sometimes fails to connect to the client. Causes?

My Arduino web server sketch sporadically fails on:
EthernetClient client = server.available();
if (client)
This morning, it connected just fine on the first run. Now, it can't connect to the client again. A couple of days ago, it worked several times, but failed several time as well. I have the shield connected via an Ethernet cable to my home router. I've verified the IP address assigned to the Arduino. I've tried ports 80 and 8080. What could be going wrong and what else can I try? Could my ISP be blocking something here? Please don't be afraid to suggest the obvious, since I know almost nothing about networks.
If relevant, here is a larger piece of the code, which loops on
Serial.println("Listening");
Code:
#include <SPI.h>
#include <Ethernet.h>n
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xF7, 0x99 };
IPAddress ip(192,168,2,5);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
String roundOpenTag = "";
String roundCloseTag = "";
void setup()
{
// Start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
int ledPin = 8;
// Initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("Setting up");
}
void loop()
{
// Listen for incoming clients
EthernetClient client = server.available();
Serial.println("Listening");
if (client)
{
Serial.println("Server available");
// An HTTP request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
Serial.println("Client connected");
if (client.available())
{
char c = client.read();
I don't see the purpose in including the rest of the sketch. I really appreciate your help.
You have a empty Seiral.begin() in your setup() function. Try removing it.
Edit:
When you call Serial.begin() you have to provide the baut rate(speed) at which you want to communicate. You can read more about the function at Arduino library page.
You had two problems in your code
You had a empty Serial.begin() function call, without any parameter
You had duplicate Serial.begin() function. You had already specified it in the beginning of the setup() function.

Resources