@@ -396,10 +396,9 @@ The central control node (Node 7) acts as the command center of the system, send
396
396
#include <Arduino_10BASE_T1S.h>
397
397
#include <SPI.h>
398
398
399
- const uint8_t MY_ID = 7; // Server is node 7
399
+ const uint8_t MY_ID = 7;
400
400
401
- // Network setup
402
- IPAddress myIP(192, 168, 42, 100 + MY_ID);
401
+ IPAddress myIP(192, 168, 42, 107);
403
402
IPAddress netmask(255, 255, 255, 0);
404
403
IPAddress gateway(192, 168, 42, 100);
405
404
@@ -411,14 +410,9 @@ void setup() {
411
410
Serial.begin(115200);
412
411
delay(1000);
413
412
414
- Serial.println("\n=== SPE LED Control Server ===");
415
- Serial.println("Commands:");
416
- Serial.println(" LED 0 - Toggle LED on Opta at node 0");
417
- Serial.println(" LED 1 - Toggle LED on Opta at node 1");
418
- Serial.println(" (etc. for other nodes)");
419
- Serial.println("\nType command and press Enter\n");
413
+ Serial.println("\nSPE LED Control Server");
414
+ Serial.println("Type: LED 0, LED 1, etc.\n");
420
415
421
- // Initialize hardware
422
416
io = new TC6::TC6_Io(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
423
417
network = new TC6::TC6_Arduino_10BASE_T1S(io);
424
418
udp = new Arduino_10BASE_T1S_UDP();
@@ -428,57 +422,39 @@ void setup() {
428
422
io->onInterrupt();
429
423
}, FALLING);
430
424
431
- if (!io->begin()) {
432
- Serial.println("IO failed!");
433
- while(1);
434
- }
425
+ io->begin();
435
426
436
427
MacAddress mac = MacAddress::create_from_uid();
437
428
T1SPlcaSettings plca(MY_ID);
438
429
T1SMacSettings mac_settings;
439
430
440
- if (!network->begin(myIP, netmask, gateway, mac, plca, mac_settings)) {
441
- Serial.println("Network failed!");
442
- while(1);
443
- }
444
-
431
+ network->begin(myIP, netmask, gateway, mac, plca, mac_settings);
445
432
network->digitalWrite(TC6::DIO::A0, false);
446
433
network->digitalWrite(TC6::DIO::A1, false);
447
434
448
- if (!udp->begin(8888)) {
449
- Serial.println("UDP failed!");
450
- while(1);
451
- }
435
+ udp->begin(8888);
452
436
453
- Serial.println("Ready! Enter LED commands: ");
437
+ Serial.println("Ready!");
454
438
}
455
439
456
440
void loop() {
457
441
network->service();
458
442
459
- // Check for user commands
460
443
if (Serial.available()) {
461
444
String cmd = Serial.readStringUntil('\n');
462
445
cmd.trim();
463
446
cmd.toUpperCase();
464
447
465
- // Check if it's a valid LED command
466
448
if (cmd.startsWith("LED ")) {
467
- int targetNode = cmd.substring(4).toInt();
468
-
469
- // Send to the target node
470
- IPAddress targetIP(192, 168, 42, 100 + targetNode);
449
+ int node = cmd.substring(4).toInt();
450
+ IPAddress targetIP(192, 168, 42, 100 + node);
471
451
472
452
udp->beginPacket(targetIP, 8888);
473
453
udp->print(cmd);
474
454
udp->endPacket();
475
455
476
- Serial.print("Sent '");
477
- Serial.print(cmd);
478
- Serial.print("' to node ");
479
- Serial.println(targetNode);
480
- } else {
481
- Serial.println("Invalid command. Use: LED 0, LED 1, etc.");
456
+ Serial.print("Sent to node ");
457
+ Serial.println(node);
482
458
}
483
459
}
484
460
}
@@ -492,41 +468,33 @@ The gateway nodes serve as protocol translators between the SPE network and RS-4
492
468
493
469
494
470
``` arduino
495
- // SPE/RS-485 Gateway Node - Forwards LED commands to Opta
471
+ // SPE/RS-485 Gateway
496
472
#include <Arduino_10BASE_T1S.h>
497
473
#include <SPI.h>
498
474
499
- const uint8_t MY_ID = 0; // Gateway node ID (change for each gateway)
475
+ const uint8_t MY_ID = 0; // Change for each gateway
500
476
501
- // Network setup
502
477
IPAddress myIP(192, 168, 42, 100 + MY_ID);
503
478
IPAddress netmask(255, 255, 255, 0);
504
479
IPAddress gateway(192, 168, 42, 100);
505
480
506
- // RS-485 control pins
507
- #define RS485_DE_PIN 7
508
- #define RS485_RE_PIN 8
509
-
510
481
TC6::TC6_Io* io;
511
482
TC6::TC6_Arduino_10BASE_T1S* network;
512
483
Arduino_10BASE_T1S_UDP* udp;
513
484
514
485
void setup() {
515
- Serial.begin(115200); // USB debug
516
- Serial1.begin(9600); // RS-485 to Opta
486
+ Serial.begin(115200);
487
+ Serial1.begin(9600);
517
488
delay(1000);
518
489
519
- Serial.print("\n=== SPE/RS-485 Gateway Node ");
520
- Serial.print(MY_ID);
521
- Serial.println(" ===");
522
- Serial.println("Forwarding LED commands to Opta");
490
+ Serial.print("\nGateway Node ");
491
+ Serial.println(MY_ID);
523
492
524
- // Setup RS-485 pins
525
- pinMode(RS485_DE_PIN , OUTPUT);
526
- pinMode(RS485_RE_PIN, OUTPUT );
527
- setTransmitMode(); // We only transmit to Opta
493
+ pinMode(7, OUTPUT); // RS485_DE
494
+ pinMode(8 , OUTPUT); // RS485_RE
495
+ digitalWrite(7, HIGH );
496
+ digitalWrite(8, HIGH);
528
497
529
- // Initialize SPE network
530
498
io = new TC6::TC6_Io(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
531
499
network = new TC6::TC6_Arduino_10BASE_T1S(io);
532
500
udp = new Arduino_10BASE_T1S_UDP();
@@ -536,79 +504,38 @@ void setup() {
536
504
io->onInterrupt();
537
505
}, FALLING);
538
506
539
- if (!io->begin()) {
540
- Serial.println("IO failed!");
541
- while(1);
542
- }
507
+ io->begin();
543
508
544
509
MacAddress mac = MacAddress::create_from_uid();
545
510
T1SPlcaSettings plca(MY_ID);
546
511
T1SMacSettings mac_settings;
547
512
548
- if (!network->begin(myIP, netmask, gateway, mac, plca, mac_settings)) {
549
- Serial.println("Network failed!");
550
- while(1);
551
- }
552
-
513
+ network->begin(myIP, netmask, gateway, mac, plca, mac_settings);
553
514
network->digitalWrite(TC6::DIO::A0, false);
554
515
network->digitalWrite(TC6::DIO::A1, false);
555
516
556
- if (!udp->begin(8888)) {
557
- Serial.println("UDP failed!");
558
- while(1);
559
- }
517
+ udp->begin(8888);
560
518
561
- Serial.println("Gateway ready !");
519
+ Serial.println("Ready !");
562
520
}
563
521
564
522
void loop() {
565
523
network->service();
566
524
567
- // Check for SPE packets
568
- int packetSize = udp->parsePacket();
569
- if (packetSize > 0) {
570
- char buffer[64];
571
- int len = udp->read((byte*)buffer, 63);
572
- buffer[len] = '\0';
525
+ if (udp->parsePacket()) {
526
+ char buffer[64] = {0};
527
+ udp->read((byte*)buffer, 63);
573
528
574
529
String cmd = String(buffer);
575
530
cmd.trim();
576
531
577
- Serial.print("SPE received: ");
578
- Serial.println(cmd);
579
-
580
- // Check if this LED command is for our node
581
- if (cmd.startsWith("LED ")) {
582
- int targetNode = cmd.substring(4).toInt();
583
- if (targetNode == MY_ID) {
584
- sendRS485("T"); // Send 'T' to toggle
585
- Serial.println("Command for this node - sent toggle to Opta");
586
- } else {
587
- Serial.println("Command for different node, ignoring");
588
- }
532
+ if (cmd == "LED " + String(MY_ID)) {
533
+ Serial1.println("T");
534
+ Serial1.flush();
535
+ Serial.println("Toggle sent");
589
536
}
590
537
}
591
538
}
592
-
593
- void setTransmitMode() {
594
- digitalWrite(RS485_RE_PIN, HIGH); // Disable receiver
595
- digitalWrite(RS485_DE_PIN, HIGH); // Enable driver
596
- delay(10);
597
- }
598
-
599
- void sendRS485(String msg) {
600
- setTransmitMode();
601
-
602
- // Clear any garbage first
603
- while(Serial1.available()) {
604
- Serial1.read();
605
- }
606
-
607
- delay(10);
608
- Serial1.println(msg);
609
- Serial1.flush();
610
- delay(10);
611
- }
612
539
```
613
540
614
541
### Opta RS-485 Interface
@@ -671,20 +598,23 @@ void loop() {
671
598
672
599
### Common Issues and Solutions
673
600
674
- ** No Communication**
675
- - Verify termination jumpers are correctly set (closed for P2P, only endpoints for multidrop)
676
- - Check cable connections and polarity
677
- - Ensure twisted pair cable is used
601
+ ** No Communication**
602
+
603
+ - Verify termination jumpers are correctly set (closed for P2P, only endpoints for multidrop)
604
+ - Check cable connections and polarity
605
+ - Ensure twisted pair cable is used
606
+
607
+ ** Intermittent Communication**
608
+
609
+ - Reduce cable length (maximum 25 m)
610
+ - Check for proper grounding
611
+ - Verify stub lengths in multidrop (< 5 cm)
678
612
679
- ** Intermittent Communication**
680
- - Reduce cable length (maximum 25 m)
681
- - Check for proper grounding
682
- - Verify stub lengths in multidrop (< 5 cm)
613
+ ** Power Issues**
683
614
684
- ** Power Issues**
685
- - When using PoDL, ensure power supply can provide sufficient current
686
- - Check voltage levels are within specification (7 - 24 VDC)
687
- - Verify Arduino board voltage compatibility
615
+ - When using PoDL, ensure power supply can provide sufficient current
616
+ - Check voltage levels are within specification (7/24 VDC)
617
+ - Verify Arduino board voltage compatibility
688
618
689
619
### LED Indicators
690
620
0 commit comments