hannahgill12
Member
How do we set the Teensy 4.1's IP address without DHCP? We are looking to set a static IP address.
#include <SPI.h>
#include <NativeEthernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
// telnet defaults to port 23
EthernetServer server(23);
EthernetClient clients[8];
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
// initialize the Ethernet device
Ethernet.begin(mac, ip, myDns, gateway, subnet);
Thank you Mark!
I’ve still got a few questions from this code now:
is the byte_mac the mac address of the teensy?
if so, how do you get the mac address from the teensy?
is the "IPAddress ip" the address that you are trying to set the teensy to?
Thank you!
Thank you Mark!
I’ve still got a few questions from this code now:
is the byte_mac the mac address of the teensy?
if so, how do you get the mac address from the teensy?
is the "IPAddress ip" the address that you are trying to set the teensy to?
Thank you!
Thank you Mark and TeensyWolf!
I believe I was able to get my Teensy's MAC address.
Does someone mind explaining more about what the following variables are in the code shared by Mark?
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
That helps a lot! Thank you very much Mark
The other device that I am intending to connect my Teensy to is a Raspberry Pi 4B. I will look into getting those "gateway" and "subnet" values from the Raspberry Pi - if anyone has any tips for that, I would love to hear them!
Cheers,
Hannah
pi@testingHost:~ $ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:42:52:85
inet addr:192.168.0.9 Bcast:192.168.0.127 Mask:255.255.255.128
inet6 addr: fe80::7dc1:32ab:b2e0:23c1/64 Scope:Link
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:218837 errors:0 dropped:0 overruns:0 frame:0
TX packets:127796 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21571976 (20.5 MiB) TX bytes:15916499 (15.1 MiB)
pi@testingHost:~ $ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 192.168.0.1
pi@testingHost:~ $ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.0.1 0.0.0.0 UG 0 0 0 wlan0
192.168.0.0 * 255.255.255.128 U 0 0 0 wlan0