Skip to content

Commit 4891ebf

Browse files
Merge pull request #802 from arduino/pedromsousalima/SPE-Shield/prelaunchfixes
fixed indentation + simplified code + getting started button fix
2 parents 79e02c8 + 809eafa commit 4891ebf

File tree

2 files changed

+49
-119
lines changed

2 files changed

+49
-119
lines changed

content/hardware/02.hero/shields/spe-shield/product.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: UNO SPE Shield
33
url_shop: https://store.arduino.cc/uno-spe-shield
44
certifications: [CE, FCC, REACH, RoHS, WEEE, UKCA]
5-
primary_button_url: https://docs.arduino.cc/tutorials/spe-shield/getting-started/
5+
primary_button_url: /tutorials/spe-shield/getting-started
66
primary_button_title: Get Started
77
productCode: '221'
88
sku: [ASX00073]

content/hardware/02.hero/shields/spe-shield/tutorials/getting-started/spe-getting-started.md

Lines changed: 48 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,9 @@ The central control node (Node 7) acts as the command center of the system, send
396396
#include <Arduino_10BASE_T1S.h>
397397
#include <SPI.h>
398398
399-
const uint8_t MY_ID = 7; // Server is node 7
399+
const uint8_t MY_ID = 7;
400400
401-
// Network setup
402-
IPAddress myIP(192, 168, 42, 100 + MY_ID);
401+
IPAddress myIP(192, 168, 42, 107);
403402
IPAddress netmask(255, 255, 255, 0);
404403
IPAddress gateway(192, 168, 42, 100);
405404
@@ -411,14 +410,9 @@ void setup() {
411410
Serial.begin(115200);
412411
delay(1000);
413412
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");
420415
421-
// Initialize hardware
422416
io = new TC6::TC6_Io(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
423417
network = new TC6::TC6_Arduino_10BASE_T1S(io);
424418
udp = new Arduino_10BASE_T1S_UDP();
@@ -428,57 +422,39 @@ void setup() {
428422
io->onInterrupt();
429423
}, FALLING);
430424
431-
if (!io->begin()) {
432-
Serial.println("IO failed!");
433-
while(1);
434-
}
425+
io->begin();
435426
436427
MacAddress mac = MacAddress::create_from_uid();
437428
T1SPlcaSettings plca(MY_ID);
438429
T1SMacSettings mac_settings;
439430
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);
445432
network->digitalWrite(TC6::DIO::A0, false);
446433
network->digitalWrite(TC6::DIO::A1, false);
447434
448-
if (!udp->begin(8888)) {
449-
Serial.println("UDP failed!");
450-
while(1);
451-
}
435+
udp->begin(8888);
452436
453-
Serial.println("Ready! Enter LED commands:");
437+
Serial.println("Ready!");
454438
}
455439
456440
void loop() {
457441
network->service();
458442
459-
// Check for user commands
460443
if (Serial.available()) {
461444
String cmd = Serial.readStringUntil('\n');
462445
cmd.trim();
463446
cmd.toUpperCase();
464447
465-
// Check if it's a valid LED command
466448
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);
471451
472452
udp->beginPacket(targetIP, 8888);
473453
udp->print(cmd);
474454
udp->endPacket();
475455
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);
482458
}
483459
}
484460
}
@@ -492,41 +468,33 @@ The gateway nodes serve as protocol translators between the SPE network and RS-4
492468

493469

494470
```arduino
495-
// SPE/RS-485 Gateway Node - Forwards LED commands to Opta
471+
// SPE/RS-485 Gateway
496472
#include <Arduino_10BASE_T1S.h>
497473
#include <SPI.h>
498474
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
500476
501-
// Network setup
502477
IPAddress myIP(192, 168, 42, 100 + MY_ID);
503478
IPAddress netmask(255, 255, 255, 0);
504479
IPAddress gateway(192, 168, 42, 100);
505480
506-
// RS-485 control pins
507-
#define RS485_DE_PIN 7
508-
#define RS485_RE_PIN 8
509-
510481
TC6::TC6_Io* io;
511482
TC6::TC6_Arduino_10BASE_T1S* network;
512483
Arduino_10BASE_T1S_UDP* udp;
513484
514485
void setup() {
515-
Serial.begin(115200); // USB debug
516-
Serial1.begin(9600); // RS-485 to Opta
486+
Serial.begin(115200);
487+
Serial1.begin(9600);
517488
delay(1000);
518489
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);
523492
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);
528497
529-
// Initialize SPE network
530498
io = new TC6::TC6_Io(SPI, CS_PIN, RESET_PIN, IRQ_PIN);
531499
network = new TC6::TC6_Arduino_10BASE_T1S(io);
532500
udp = new Arduino_10BASE_T1S_UDP();
@@ -536,79 +504,38 @@ void setup() {
536504
io->onInterrupt();
537505
}, FALLING);
538506
539-
if (!io->begin()) {
540-
Serial.println("IO failed!");
541-
while(1);
542-
}
507+
io->begin();
543508
544509
MacAddress mac = MacAddress::create_from_uid();
545510
T1SPlcaSettings plca(MY_ID);
546511
T1SMacSettings mac_settings;
547512
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);
553514
network->digitalWrite(TC6::DIO::A0, false);
554515
network->digitalWrite(TC6::DIO::A1, false);
555516
556-
if (!udp->begin(8888)) {
557-
Serial.println("UDP failed!");
558-
while(1);
559-
}
517+
udp->begin(8888);
560518
561-
Serial.println("Gateway ready!");
519+
Serial.println("Ready!");
562520
}
563521
564522
void loop() {
565523
network->service();
566524
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);
573528
574529
String cmd = String(buffer);
575530
cmd.trim();
576531
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");
589536
}
590537
}
591538
}
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-
}
612539
```
613540

614541
### Opta RS-485 Interface
@@ -671,20 +598,23 @@ void loop() {
671598

672599
### Common Issues and Solutions
673600

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)
678612

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**
683614

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
688618

689619
### LED Indicators
690620

0 commit comments

Comments
 (0)