> For the complete documentation index, see [llms.txt](https://docs.tychos.org/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tychos.org/docs/learn/hardware-devices.md).

# Connecting Hardware Devices

Tychos supports two types of hardware devices that can feed live sensor data directly into your simulation: **Vernier wireless sensors** (via Bluetooth) and **USB serial devices** (Micro:bit, Arduino, Raspberry Pi, ESP32, and others).

Open **Devices** from the **Settings** panel to connect and manage devices:

<figure><img src="/files/oIqdYES211wwfeVoWICi" alt=""><figcaption></figcaption></figure>

***

## Vernier Wireless Sensors

Vernier's wireless sensors connect over Bluetooth LE using Vernier's GoDirect technology. Click **+ Add Vernier** to scan for nearby sensors.

**Compatible devices:** Any Vernier GoDirect wireless sensor (force, temperature, motion, pH, etc.)

**Requirements:** Your browser must support Web Bluetooth (Chrome or Edge on desktop).

***

## USB Serial Devices

Click **+ Connect Serial Device** to connect any microcontroller that outputs data over USB as text. This uses the Web Serial API built into Chrome and Edge.

**Compatible devices include:**

* Micro:bit
* Arduino (Uno, Nano, Mega, etc.)
* Raspberry Pi (via USB serial)
* ESP32 / ESP8266
* Any device that sends text over a serial port

### Data Format

Your device should send data over serial at **115200 baud** in one of these formats:

**JSON object** (recommended for multiple values):

```
{"temperature": 22.5, "pressure": 1013.2}
```

**Key-value pairs** (one per line):

```
temperature:22.5
pressure:1013.2
```

**CSV** (values are labeled `col_0`, `col_1`, etc.):

```
22.5,1013.2
```

***

## Reading Device Data in Code

Once a device is connected, use `scenario.get_device(index)` to access it in your simulation code. Devices are indexed in the order they were connected (starting at `0`).

```python
# Get the first connected device
sensor = scenario.get_device(0)

# Read a value from the device
temp = sensor.data["temperature"]
```

The `data` dictionary is updated automatically each frame as new serial data arrives.

### Example (Python): Plotting live temperature

```python
# Setup
g = graph(title="Temperature")
sensor = scenario.get_device(0)

# Loop
if sensor:
    temp = sensor.data.get("temperature", 0)
    g.plot(x=t, y=temp, color="red")
```

### Multiple devices

```python
vernier = scenario.get_device(0)   # first connected
arduino = scenario.get_device(1)   # second connected

force = vernier.data.get("Force", 0)
angle = arduino.data.get("angle", 0)
```

***

## Arduino Example Sketch

Here is a minimal Arduino sketch that sends data in JSON format:

```cpp
void setup() {
  Serial.begin(115200);
}

void loop() {
  float temperature = analogRead(A0) * (5.0 / 1023.0) * 100.0;
  Serial.print("{\"temperature\":");
  Serial.print(temperature, 2);
  Serial.println("}");
  delay(100);
}
```

***

## Micro:bit Example (MakeCode / Python)

In MicroPython on the Micro:bit:

```python
from microbit import *
import utime

uart.init(baudrate=115200)

while True:
    x = accelerometer.get_x()
    y = accelerometer.get_y()
    uart.write('{"x":' + str(x) + ',"y":' + str(y) + '}\n')
    utime.sleep_ms(100)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tychos.org/docs/learn/hardware-devices.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
