This is going to be pretty specific to this one ESP32 board, TTGO TDISPLAY. I am able to get the RC522 working with other ESP32's.
For reference of SPI pins on this board: https://github.com/Xinyuan-LilyGO/TTGO-T-Display/issues/32
Right now, the RC522 is being recognized and returns the firmware number successfully, but it will not read cards. I have verified it works on other devices.
MISO - 27
MOSI - 26
CLK - 25
CS - 33
RST - 17
I am setting RST to HIGH, as on other ESP32 devices it reads HIGH and works.
I do not know if I'm missing a step (something maybe to disable SPI on the onboard display) or if there's something different about SPI on this board.I'm checking SS for both devices, the OLED is 1 as is the RC522... However, the RC522 is still 1 on the other ESP32 that works...
Not sure if this is different on the TTGO because there are two SPI's going, OLED and RC522. I believe they are both using different SPI busses, HSPI and VSPI. The OLED pinouts are not accessible, so I'm using the other set.
Code below
#include <SPI.h>
#include <MFRC522.h>
#include <TFT_eSPI.h> // Hardware-specific library
#define RST_PIN 17 // Configurable, see typical pin layout above
#define SS_PIN 33 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
pinMode(RST_PIN, OUTPUT);
digitalWrite(RST_PIN, HIGH);
Serial.println("HELLO");
Serial.println(digitalRead(RST_PIN));
tft.init();
tft.fillScreen(TFT_WHITE);
SPI.begin(25,27,26); // Init SPI bus CLK, MISO, MOSI
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
Disregard. Turns out I had a bad ground pin. Once I changed to a different ground, it worked fine.
Code above should work for anyone trying to get RC522 working on TTGO TDISPLAY. Just check your connections.
Related
The Problem:
Hi, First of all, i am no expert at C++.
I seem can't find any of the guide(or documentation) of modbusMaster especially for this particular library. Which explains all the class method uses.
I use this library because it supports stream class. not like official library or others. Therefore, i can use softwareSerial to add more serial for rs485.
I am using Arduino pro mini, that's why i need software serial. And this Max485 module:
I am very sure everything is connected properly, thus my aim is to read coil from a Chinese brand ultrasonic level meter which the guide says:
Here's the program what i am trying to do:
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
/*!
We're using a MAX485-compatible RS485 Transceiver.
Rx/Tx is hooked up to the hardware serial port at 'Serial'.
The Data Enable and Receiver Enable pins are hooked up as follows:
*/
#define MAX485_DE 9
#define MAX485_RE_NEG 8
//for software serial
#define RO_RX 7
#define DI_TX 6
// instantiate ModbusMaster object
ModbusMaster node;
// RX, TX on softser
SoftwareSerial mySerial(RO_RX, DI_TX);
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
// Init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// for serial monitoring on PC
Serial.begin(115200);
// Modbus communication runs at 9600 baud
mySerial.begin(9600);
// Modbus slave ID 1 and pass the software serial
node.begin(1, mySerial);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
Serial.println("init done...");
}
void loop()
{
// now, i'm kinda lost here..
delay(100);
Serial.println("loop end.");
}
I am confused with most of the class method without a proper explanation.
modbusObj.readWriteMultipleRegisters();
modbusObj.writeSingleRegister();
modbusObj.setTransmitBuffer();
modbusObj.readCoils();
modbusObj.writeMultipleRegisters();
modbusObj.readHoldingRegisters();
// etc..
They had no documentation. Well, Some method names are self explanatory but not about the arguments.I am trying just to read the holding register.
TL;DR:
I want to read the level meter's distance data, but the library doesn't provide a proper documentation.
Nb:
nothing wrong with the ultrasonic device, tested in PC to read holding register with some modbus tool and hooked up to rs485 to usb and working!
this question intended in stack overflow rather than stack-electrical-engineering because I am mainly asking about the code.
I've been discussing it with someone in a local facebook forum that said he's successfully utilizing the lib alongside soft-serial and pro-mini.
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.
When I compile my program i get this message
Sketch uses 7,074 bytes (21%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,033 bytes (50%) of dynamic memory, leaving 1,015 bytes for local variables. Maximum is 2,048 bytes.
What do this message states?
this is my code
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;//go to start of loop if there is no card present
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;//if ReadCardSerial returns 1, the "uid" struct (see MFRC522.h lines 238-45)) contains the ID of the read card.
}
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
and I'm getting this message on blinking led long pin 13 too
If you look at this question you'll see that without care, constant strings like "Scan PICC to see UID and type..." will use SRAM (dynamic memory) and not flash (program storage space).
It is a message that informs you on the state of arduino's memory.
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.
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...");