Keyboard Shortcuts
Likes
- Jmriusers
- Messages
Search
I’m a bit surprised that didn’t work. Let me do some experiments…
Bob On Apr 30, 2023, at 4:32 PM, Tim Kelley <tim.kelley@...> wrote:— Bob Jacobsen rgj1927@... |
MFRC522, Ethernet/Serial, Nano/Uno/Mega Ughhh! Disregard the last sketch I just posted. Use this one instead. Same functionality as described, but I inadvertently left out the IP address line(s). My apologies.? ? // Import Libraries
#include <SPI.h>? ? ? ? ? ?// SPI library for communicating with the MFRC522 reader
#include <MFRC522.h>? ? ? ?// MFRC522 library for reading RFID cards
#include <Ethernet.h>? ? ? // Ethernet library for the Ethernet shield
?
// Ethernet configuration
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, 1, 177); // Replace with the desired IP address
unsigned int serverPort = 8888;? // Replace with the desired port number
?
EthernetServer server(serverPort);
?
// Define the SS (Slave Select) and RST (Reset) pins for each reader
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO)
const uint8_t ssPins[] = {5, 6, 7, A0, A1, A2};
const uint8_t rstPins[] = {4, 8, 9, A3, A4, A5};
const uint8_t readerAssignment[] = {1, 2, 3, 4, 5, 6}; // Assign reader numbers based on SS and RST pins
#elif defined(ARDUINO_AVR_MEGA2560)
const uint8_t ssPins[] = {5, 6, 7, 8, 9, A0, A1, A2};
const uint8_t rstPins[] = {22, 23, 24, 25, 26, 27, 28, 29};
const uint8_t readerAssignment[] = {1, 2, 3, 4, 5, 6, 7, 8}; // Assign reader numbers based on SS and RST pins
#endif
?
const int numReaders = sizeof(ssPins) / sizeof(ssPins[0]);
const char readerID[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
?
struct RFIDReader {
? char id;
? uint8_t ssPin;
? uint8_t rstPin;
? MFRC522 mfrc522;
? byte nuid[7];
?
? RFIDReader() : id(0), ssPin(0), rstPin(0), mfrc522(MFRC522(0, 0)) {}
};
?
RFIDReader readers[numReaders];
EthernetClient client;
bool isEthernetConnected = false;
?
void setup() {
? Serial.begin(9600);
? SPI.begin();
? pinMode(10, OUTPUT);
? digitalWrite(10, HIGH);
?
? // Set pin 53 as OUTPUT for the Arduino Mega 2560
? #if defined(ARDUINO_AVR_MEGA2560)
? ? pinMode(53, OUTPUT);
? #endif
?
? pinMode(4, OUTPUT);
? digitalWrite(4, HIGH);
?
? if (Ethernet.begin(mac, ip) == 1) {
? ? isEthernetConnected = true;
? ? delay(1000);
? } else {
? ? Serial.println("Ethernet shield not connected or network not available");
? ? isEthernetConnected = false;
? }
?
? for (uint8_t i = 0; i < numReaders; i++) {
? ? readers[i].ssPin = ssPins[i];
? ? readers[i].rstPin = rstPins[i];
? ? readers[i].id = readerID[readerAssignment[i] - 1]; // Assign the reader ID based on readerAssignment array
? ? readers[i].mfrc522 = MFRC522(readers[i].ssPin, readers[i].rstPin);
? ? readers[i].mfrc522.PCD_Init();
? ? readers[i].mfrc522.PCD_SetAntennaGain(readers[i].mfrc522.RxGain_max);
?
? ? // Print debugging information
? ? Serial.print("Reader ");
? ? Serial.print(readers[i].id);
? ? Serial.print(" detected on SS pin ");
? ? Serial.println(readers[i].ssPin);
? }
?
? if (isEthernetConnected) {
? ? server.begin();
? }
?
? // Blink the LED to indicate the number of detected readers
? pinMode(LED_BUILTIN, OUTPUT);
? for (int i = 0; i < numReaders; i++) {
? ? digitalWrite(LED_BUILTIN, HIGH);
? ? delay(300);
? ? digitalWrite(LED_BUILTIN, LOW);
? ? delay(300);
? }
}
?
void loop() {
? if (isEthernetConnected) {
? ? if (!client.connected()) {
? ? ? client.stop();
? ? ? client = server.accept();
? ? ? if (client) {
? ? ? ? Serial.println("Client connected");
? ? ? }
? ? }
? }
?
? for (uint8_t i = 0; i < numReaders; i++) {
? ? if (readers[i].mfrc522.PICC_IsNewCardPresent() && readers[i].mfrc522.PICC_ReadCardSerial()) {
? ? ? for (uint8_t j = 0; j < readers[i].mfrc522.uid.size; j++) {
? ? ? ? readers[i].nuid[j] = readers[i].mfrc522.uid.uidByte[j];
? ? ? }
?
? ? ? byte checksum = readers[i].nuid[0];
? ? ? for (uint8_t j = 1; j < 5; j++) {
? ? ? ? checksum ^= readers[i].nuid[j];
? ? ? }
?
? ? ? // Send output to Serial connection
? ? ? Serial.write(readers[i].id);
?
? ? ? if (isEthernetConnected && client.connected()) {
? ? ? ? // Send output to Ethernet client
? ? ? ? client.write(readers[i].id);
? ? ? }
?
? ? ? for (uint8_t j = 0; j < 5; j++) {
? ? ? ? // Send output to Serial connection
? ? ? ? Serial.print(readers[i].nuid[j] < 0x10 ? "0" : "");
? ? ? ? Serial.print(readers[i].nuid[j], HEX);
?
? ? ? ? if (isEthernetConnected && client.connected()) {
? ? ? ? ? // Send output to Ethernet client
? ? ? ? ? client.print(readers[i].nuid[j] < 0x10 ? "0" : "");
? ? ? ? ? client.print(readers[i].nuid[j], HEX);
? ? ? ? }
? ? ? }
?
? ? ? // Send output to Serial connection
? ? ? Serial.print(checksum < 0x10 ? "0" : "");
? ? ? Serial.print(checksum, HEX);
?
? ? ? if (isEthernetConnected && client.connected()) {
? ? ? ? // Send output to Ethernet client
? ? ? ? client.print(checksum < 0x10 ? "0" : "");
? ? ? ? client.print(checksum, HEX);
? ? ? }
?
? ? ? // Send output to Serial connection
? ? ? Serial.write(0x0D);
? ? ? Serial.write(0x0A);
? ? ? Serial.write('>');
?
? ? ? if (isEthernetConnected && client.connected()) {
? ? ? ? // Send output to Ethernet client
? ? ? ? client.write(0x0D); // CR
? ? ? ? client.write(0x0A); // LF
? ? ? ? client.write('>');? // ETX replaced by '>'
? ? ? }
?
? ? ? readers[i].mfrc522.PICC_HaltA();
? ? ? readers[i].mfrc522.PCD_StopCrypto1();
? ? }
? }
} Tom |
On Sun, Apr 30, 2023 at 05:38 PM, <stephenjohnson500@...> wrote:
MFRC522, Uno, Ethernet Steve, It should now work as expected, with the following behavior: If an Ethernet shield is not connected or the shield is not connected to the network, the sketch will operate in Serial mode and send tag information to the Serial Monitor. If an Ethernet shield is connected and the shield is connected to the network, the sketch will operate in both Serial and Ethernet modes, sending tag information to the Serial Monitor and any connected Ethernet clients. When the sketch is uploaded to an Arduino Nano, Uno or Mega, the LED will blink during startup to indicate the number of detected readers. Please test the sketch and see if it works as intended in your setup. // Import Libraries
#include <SPI.h>? ? ? ? ? ?// SPI library for communicating with the MFRC522 reader
#include <MFRC522.h>? ? ? ?// MFRC522 library for reading RFID cards
#include <Ethernet.h>? ? ? // Ethernet library for the Ethernet shield
?
// Ethernet configuration
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
unsigned int serverPort = 8888;? // Replace with the desired port number
EthernetServer server(serverPort);
?
// Define the SS (Slave Select) and RST (Reset) pins for each reader
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO)
const uint8_t ssPins[] = {5, 6, 7, A0, A1, A2};
const uint8_t rstPins[] = {4, 8, 9, A3, A4, A5};
const uint8_t readerAssignment[] = {1, 2, 3, 4, 5, 6}; // Assign reader numbers based on SS and RST pins
#elif defined(ARDUINO_AVR_MEGA2560)
const uint8_t ssPins[] = {5, 6, 7, 8, 9, A0, A1, A2};
const uint8_t rstPins[] = {22, 23, 24, 25, 26, 27, 28, 29};
const uint8_t readerAssignment[] = {1, 2, 3, 4, 5, 6, 7, 8}; // Assign reader numbers based on SS and RST pins
#endif
?
const int numReaders = sizeof(ssPins) / sizeof(ssPins[0]);
const char readerID[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
?
struct RFIDReader {
? char id;
? uint8_t ssPin;
? uint8_t rstPin;
? MFRC522 mfrc522;
? byte nuid[7];
?
? RFIDReader() : id(0), ssPin(0), rstPin(0), mfrc522(MFRC522(0, 0)) {}
};
?
RFIDReader readers[numReaders];
EthernetClient client;
bool isEthernetConnected = false;
?
void setup() {
? Serial.begin(9600);
? SPI.begin();
? pinMode(10, OUTPUT);
? digitalWrite(10, HIGH);
?
? // Set pin 53 as OUTPUT for the Arduino Mega 2560
? #if defined(ARDUINO_AVR_MEGA2560)
? ? pinMode(53, OUTPUT);
? #endif
?
? pinMode(4, OUTPUT);
? digitalWrite(4, HIGH);
?
? if (Ethernet.begin(mac) == 1) {
? ? isEthernetConnected = true;
? ? delay(1000);
? } else {
? ? Serial.println("Ethernet shield not connected or network not available");
? ? isEthernetConnected = false;
? }
?
? for (uint8_t i = 0; i < numReaders; i++) {
? ? readers[i].ssPin = ssPins[i];
? ? readers[i].rstPin = rstPins[i];
? ? readers[i].id = readerID[readerAssignment[i] - 1]; // Assign the reader ID based on readerAssignment array
? ? readers[i].mfrc522 = MFRC522(readers[i].ssPin, readers[i].rstPin);
? ? readers[i].mfrc522.PCD_Init();
? ? readers[i].mfrc522.PCD_SetAntennaGain(readers[i].mfrc522.RxGain_max);
?
? ? // Print debugging information
? ? Serial.print("Reader ");
? ? Serial.print(readers[i].id);
? ? Serial.print(" detected on SS pin ");
? ? Serial.println(readers[i].ssPin);
? }
?
? if (isEthernetConnected) {
? ? server.begin();
? }
?
? // Blink the LED to indicate the number of detected readers
? pinMode(LED_BUILTIN, OUTPUT);
? for (int i = 0; i < numReaders; i++) {
? ? digitalWrite(LED_BUILTIN, HIGH);
? ? delay(300);
? ? digitalWrite(LED_BUILTIN, LOW);
? ? delay(300);
? }
}
?
void loop() {
? if (isEthernetConnected) {
? ? if (!client.connected()) {
? ? ? client.stop();
? ? ? client = server.accept();
? ? ? if (client) {
? ? ? ? Serial.println("Client connected");
? ? ? }
? ? }
? }
?
? for (uint8_t i = 0; i < numReaders; i++) {
? ? if (readers[i].mfrc522.PICC_IsNewCardPresent() && readers[i].mfrc522.PICC_ReadCardSerial()) {
? ? ? for (uint8_t j = 0; j < readers[i].mfrc522.uid.size; j++) {
? ? ? ? readers[i].nuid[j] = readers[i].mfrc522.uid.uidByte[j];
? ? ? }
?
? ? ? byte checksum = readers[i].nuid[0];
? ? ? for (uint8_t j = 1; j < 5; j++) {
? ? ? ? checksum ^= readers[i].nuid[j];
? ? ? }
?
? ? ? // Send output to Serial connection
? ? ? Serial.write(readers[i].id);
?
? ? ? if (isEthernetConnected && client.connected()) {
? ? ? ? // Send output to Ethernet client
? ? ? ? client.write(readers[i].id);
? ? ? }
?
? ? ? for (uint8_t j = 0; j < 5; j++) {
? ? ? ? // Send output to Serial connection
? ? ? ? Serial.print(readers[i].nuid[j] < 0x10 ? "0" : "");
? ? ? ? Serial.print(readers[i].nuid[j], HEX);
?
? ? ? ? if (isEthernetConnected && client.connected()) {
? ? ? ? ? // Send output to Ethernet client
? ? ? ? ? client.print(readers[i].nuid[j] < 0x10 ? "0" : "");
? ? ? ? ? client.print(readers[i].nuid[j], HEX);
? ? ? ? }
? ? ? }
?
? ? ? // Send output to Serial connection
? ? ? Serial.print(checksum < 0x10 ? "0" : "");
? ? ? Serial.print(checksum, HEX);
?
? ? ? if (isEthernetConnected && client.connected()) {
? ? ? ? // Send output to Ethernet client
? ? ? ? client.print(checksum < 0x10 ? "0" : "");
? ? ? ? client.print(checksum, HEX);
? ? ? }
?
? ? ? // Send output to Serial connection
? ? ? Serial.write(0x0D);
? ? ? Serial.write(0x0A);
? ? ? Serial.write('>');
?
? ? ? if (isEthernetConnected && client.connected()) {
? ? ? ? // Send output to Ethernet client
? ? ? ? client.write(0x0D); // CR
? ? ? ? client.write(0x0A); // LF
? ? ? ? client.write('>');? // ETX replaced by '>'
? ? ? }
?
? ? ? readers[i].mfrc522.PICC_HaltA();
? ? ? readers[i].mfrc522.PCD_StopCrypto1();
? ? }
? }
} Tom |
Nano Connectivity
Tom, Blair, All, As you have already guessed, I'm leaning towards having a 'plug in' Nano arrangement of the proposed PCB. This is fine for a Serial output. If we wanted the network connection, which I think is a very good idea, then maybe using an ENC28J60 Ethernet Shield that the Nano plugs into is an option? Everything is all on the board still. What do you think? Is this an easy option? I'm not sure if there is any/much interest in a WiFi version, but I was thinking it might be nice to make provision for it in the form of a Node MCU such as an ESP-01 (ESP8266 based). They are certainly very cheap, but their voltage requirements would need additional circuitry on the PCB. I'm not sure how big they are, but for ?2.00, I might just get one to see! Being a separate unit, they could of course be used with the Uno and Mega if people didn't want to buy the WiFi enabled version of those. Just throwing a few thoughts in. Steve |
On Sun, Apr 30, 2023 at 10:56 PM, miktrain wrote:
Steve,Tony, Your absolutely right, DIP switches might be an easier option! No jumpers getting lost in the carpet again!? As Tom mentioned DIL sockets for any IC's are also a must (we might need to use a 74HC4051 multiplexer IC). Keep the thoughts coming. Steve |
MFRC522, WeMos, WiFi
Tom, so first of all, I'm now a bit unsure about what I'm suppose to be connecting the SCK, MOSI and MISO to? In the event, I tried both, plus connected the reader to all four combinations. The result was the same as before. That is, it connects to the Wi|Fi and the Serial Monitor show the connection SSID and IP Address. Like the Ethernet sketch, it doesn't do anything else until connected to JMRI. When it does, it says 'New Client Connected', then rapidly goes through 'Checking Reader A' etc. etc. It does not get as far as 'Reading Tag on Reader'. As I mentioned in an earlier post, I know the WeMos can be tricky and felt a move to a different method might prove more fruitful. So, I have ordered a generic clone Uno WiFi. So it should perform like the 'genuine article'. This might be a better move as the? Uno WiFi has more connectivity and we should be up to seven readers again, hopefully. It might take up to a couple of weeks to get here, but I thought it worth a try and it might be more straightforward. Steve |
MFRC522, Uno, Ethernet
Tom, thanks for the latest sketch, which I call v6. Whatever you did fixed the problem, it now just detects the connected readers. I have tried v6 on two Uno/Ethernet combos and they both work. However (there's always one of those isn't there!), a couple of curious observations. If the sketch is uploaded to just an Uno, it detects the reader(s), but doesn't read tags.. If the sketch is uploaded to an Uno with an Ethernet Shield attached, it detects the reader(s), but doesn't read any tags. If the Uno/Ethernet Shield are now connected to the network, it does work and read tags both with JMRIs network connection and on the Serial Monitor. I don't yet have a separate power supply for the Uno, so can't check the Serial only with Arduino IDE running as it's two applications trying to use the same Com Port. I sort of expected the sketch to work in Serial Mode if a) no shield was attached and b) if the shield was attached but not connected to the network. I think this was what was frustrating me yesterday. In the interests of 'one size fits all', it would have been good if the sketch could do this. If not, then we still have the 8 Reader Serial Only sketch to fall back on. Steve |
Locked
Re: What would it take to enable "read full page" with Programming on the main? (when capable). Anyone have thoughts about thish?
Scott
Digitrax Transponding does read full pages, read all sheets etc etc. So why railcom wouldn't I don't know.? I would have to borrow back my roco stuff to check that. Steve G. |
Tim Kelley
Thanks Bob, Really appreciate the help...........!!
I changed the reset section of the TCS Wow Steam 04. xml decoder file to this......... I was trying to get DecoderPro to use Direct Byte Mode instead of Paged Mode. Maybe I messed this up! I swapped lines 2 - 3... ????? <resets> ??????? <mode>DIRECTMODE</mode> ??????? <mode>PAGEMODE</mode> ??????? <mode>OPSBYTEMODE</mode> ??????? <factReset label="Entire decoder (except speed table)" CV="8" default="2"/> ??????? <factReset label="Entire decoder (except address and speed table)" CV="T2CV.5.0" default="2"/> ??????? <factReset label="All sound settings" CV="T2CV.5.0" default="3"/> ??????? <factReset label="Sound Function mappings" CV="T2CV.5.0" default="4"/> ??????? <factReset label="Chuff timing" CV="T2CV.5.0" default="5"/> ??????? <factReset label="Sound CV's" CV="T2CV.5.0" default="6"/> ??????? <factReset label="Sound type volumes" CV="T2CV.5.0" default="7"/> ??????? <factReset label="User Preset 1" CV="T2CV.5.0" default="8"/> ??????? <factReset label="User Preset 2" CV="T2CV.5.0" default="9"/> ??????? <factReset label="User Preset 3" CV="T2CV.5.0" default="10"/> ?? ???? ??? <factReset label="Quick Lighting Preset: Standard Ditch Lights" CV="8" default="10"/> ?? ???? ??? <factReset label="Quick Lighting Preset: Standard Trolley" CV="8" default="11"/> ?? ???? ??? <factReset label="Quick Lighting Preset: Modified Trolley" CV="8" default="12"/> ????? </resets> Here's what got spit out in LocoNet monitor when I did a Reset / Factory Reset / USER PRESET 1........... I noticed it is still operating in paged mode even though I switched things around so that it would prefer Direct Mode. At least that's what I thought I did.......... Byte Write in Paged Mode on Service Track: CV201 value 5 (0x05, 00000101b). LONG_ACK: The Slot Write command was accepted. Programming Response: Write Byte in Paged Mode on Service Track Was Successful: CV201 value 5 (0x05, 00000101b). Byte Write in Paged Mode on Service Track: CV202 value 0 (0x00, 00000000b). LONG_ACK: The Slot Write command was accepted. Programming Response: Write Byte in Paged Mode on Service Track Was Successful: CV202 value 0 (0x00, 00000000b). Byte Write in Paged Mode on Service Track: CV203 value 0 (0x00, 00000000b). LONG_ACK: The Slot Write command was accepted. Programming Response: Write Byte in Paged Mode on Service Track Was Successful: CV203 value 0 (0x00, 00000000b). Byte Write in Paged Mode on Service Track: CV204 value 8 (0x08, 00001000b). LONG_ACK: The Slot Write command was accepted. Programming Response: Write Byte in Paged Mode on Service Track Was Successful: CV204 value 8 (0x08, 00001000b). So what do you think? Any ideas? Thanks, Tim |
开云体育Trouble being, who else, but a user, is best placed to extend the MX690-699 decoder files ?? They have a different manual to the MX640-660 decoders, so there may be differences ?? ? Yes, they’re complex decoders, but there’s no getting round that.? ??Hence suggestion of review when changes are done to look at it.? ? ? Nigel ? ? From: [email protected] <[email protected]>
On Behalf Of Phil G
Sent: 30 April 2023 17:50 To: [email protected] Subject: Re: [jmriusers] Zimo Decoder MS950 and MS990 Definitions #zimo ? Helpful as this is I’m wondering whether Zimo decoders are the best place to start learning decoder definitions?? ? There are many (many) advanced JMRI techniques in there….. ? Is there something simpler the OP could start with? ? Phil G
|
Locked
What would it take to enable "read full page" with Programming on the main? (when capable). Anyone have thoughts about thish?
I have RailCom readers on my mainline tracks. All the turnout blocks are wired into the common block on the readers (I have two zones and two readers - DR5088RC's). I also have many LokSound decoders. The Lok Programmer (using their proprietary process) can read a LokSound decoder in just a few seconds. JMRI on the programming track takes about an hour and a half to read all CV's. Programming on the main with JMRI, I can go to the CV's page and I can read the values as fast as I can click on the button. I suspect it would be far faster to do a read full page on the main if it were enabled. Would it be possible to add an option to enable this.
I am aware that it would only apply to 1) Digitrax decoders with transponding enabled in a block where there is a transponding reader (BXP88, BXPA1, BDL168 with appropriate RX-4's) or 2) RailCom enabled decoders (as far as I know that includes only ESU and TCS decoders - there may be others) with an appropriate RailCom reader for the applicable blocks. Should this be an option that users could enable?? Scott Walton |
Locked
Re: Jmri printing issue
#operationspro
Hi Dan. How do I print the attached Trains sheet in JMRI? I looked through the window help but either missed it or it’s not in that area.?
thanks, Frank.? -- Frank Kenny
Central Pacific Railway - CPRX
310-344-9145
Los Angeles area
Instagram:?
Facebook:?
Blog:?? ?(Updated occasionally)
|
Guys,
OK, so the best bet, I think, would be to make liberal use of jumpers and screw terminals for all external connections. Solder pads are great for those of us who DO this stuff, but not for an average user. IC sockets are also a BIG plus. IMHO, what we need to do first is hash out exactly WHAT we want this PCB to accomplish and allow us/others to do. Then we can figure out how to best do that. Tom |