This application allows remote control of a transmitter based on the QN8066 through a Python program using a Socket connection. The Arduino sketch for the NANO 33 IoT implements a server that connects to a Wi-Fi network and listens on port 8066. The Python application, in turn, connects to the server or service provided by the NANO 33 IoT and sends configuration commands to the QN8066 transmitter.
QN8066 Pin | Nano 33 IoT Pin | Description |
---|---|---|
VCC | 3.3V | Power supply |
GND | GND | Ground |
SDA (pin 2) | A4 | I2C Data |
SCL (pin 1) | A5 | I2C Clock |
QN8066_CONTROLLER.ino
to your Nano 33 IoTWiFi.localIP()
(typically 10.0.0.1)import socket
import time
# Connection settings
HOST = '10.0.0.1' # Arduino IP address
PORT = 8066 # Socket port
def connect_to_arduino():
try:
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((HOST, PORT))
return client
except Exception as e:
print(f"Connection error: {e}")
return None
def send_command(client, command):
try:
client.send(command.encode('utf-8'))
response = client.recv(1024).decode('utf-8')
return response
except Exception as e:
print(f"Communication error: {e}")
return None
# Example usage
if __name__ == "__main__":
client = connect_to_arduino()
if client:
# Set frequency to 106.9 MHz
response = send_command(client, "FREQ:1069")
print(f"Frequency response: {response}")
# Set Program Service
response = send_command(client, "PS:TEST FM")
print(f"PS response: {response}")
# Set Radio Text
response = send_command(client, "RT:Arduino Nano 33 IoT Controller")
print(f"RT response: {response}")
client.close()
The Arduino accepts the following socket commands:
Command | Format | Description | Example |
---|---|---|---|
FREQ | FREQ:xxxx | Set frequency (in tenths of MHz) | FREQ:1069 (106.9 MHz) |
PS | PS:text | Set Program Service (max 8 chars) | PS:TEST FM |
RT | RT:text | Set Radio Text (max 32 chars) | RT:Hello World |
POWER | POWER:x | Set power level | POWER:3 |
STATUS | STATUS | Get current status | STATUS |
NANO_IOT_SOCKET/
├── README.md # This file
├── QN8066_CONTROLLER/
│ └── QN8066_CONTROLLER.ino # Arduino sketch
└── QN8066_PYTHON/
└── qn8066_client.py # Python client example
You can extend the Arduino code to support additional commands:
// In Arduino sketch
if (receivedData.startsWith("MYCMD:")) {
String value = receivedData.substring(6);
// Process custom command
client.println("OK");
}
The current implementation supports one client at a time. For multiple clients, consider using threading in Python and connection management in Arduino.