> Documentation index: https://nao-rs.lukaloehr.com/llms.txt, a list of every page in this documentation.

# Head devices

> The nine chips on the head's I2C bus, their addresses, what one bus cycle sends, and the LoLA quirks nao-rs keeps on the wire.

On the NAO6, LoLA (not HAL) drives the head. Its devices sit behind a USB-I2C
bridge in the head, which Linux exposes as an I2C bus; udev links it as
`/dev/i2c-head` (it is `/dev/i2c-9` on our robot). nao-rs drives the same nine
chips with the same bytes, one transaction per cycle.

## The chips

| Address (7-bit) | Address (8-bit) | Chip | Role |
| --- | --- | --- | --- |
| `0x66` | `0xCC` | TLC59116 | Eye LEDs, blue |
| `0x64` | `0xC8` | TLC59116 | Eye LEDs, green |
| `0x62` | `0xC4` | TLC59116 | Eye LEDs, red |
| `0x61` | `0xC2` | TLC59116 | Left ear LEDs |
| `0x60` | `0xC0` | TLC59116 | Right ear LEDs |
| `0x65` | `0xCA` | TLC59116 | Skull LEDs |
| `0x28` | `0x50` | CAP1203 | The three head touch pads |
| `0x40` | `0x80` | INA230 | Head power monitor: voltage, current, power |
| `0x48` | `0x90` | TMP100 | Face board temperature |

The LED drivers' channel mapping is on the [LEDs](https://nao-rs.lukaloehr.com/hardware/leds.md) page.

## Start-up

The devices are created in the order of the table. Each LED driver starts with
its register image only, without bus traffic. The touch controller, the power
monitor and the temperature sensor get their register settings in 2-byte
writes, one transfer each. The start-up takes about 70 ms, most of it the
touch controller's calibration.

## One bus cycle

One cycle is one `I2C_RDWR` transfer with 16 messages, or 18 when the
temperature is due:

| Device | Messages |
| --- | --- |
| 6 LED drivers | One 30-byte write each: the auto-increment register byte, then all 29 registers from `MODE1` to `IREF`. Only the PWM bytes change |
| Touch controller | Read the sensor input status (1 byte), then write 0 to the main control register, which clears the latched status |
| Power monitor | Three register reads (bus voltage, power, current), then the configuration write |
| Temperature sensor | One read, when more than 300 ms have passed since the last one (about every 20th to 25th cycle) |

A transfer takes about 6 ms on the bus (5.8 ms measured with nao-rs). The state
a cycle returns is decoded from the *previous* transfer, as in LoLA. After a
failed transfer, the next transfers are split into smaller ones for a while.

## LED current

Each LED driver's output current comes from its `IREF` register:

| Chip | Current | `IREF` |
| --- | --- | --- |
| Eyes (3 chips) | 5 mA | `0x30` |
| Ears (2 chips) | 12 mA | `0xF3` |
| Skull | 6 mA | `0x22` |

## LoLA quirks kept on the wire

nao-rs sends what LoLA sends, including two mistakes, because changing bytes
the chips have always received is a change we'd have to test separately:

- The power monitor's reset value is written in the wrong byte order, so the
  chip receives `0x0080` and is never reset.
- Its configuration word shifts the averaging and conversion-time fields by
  11, 8 and 5 bits instead of the data sheet's 9, 6 and 3. The robot receives
  `0x1487`.

## Touch pads

The touch controller reports three channels. The runtime's state lists them as
front, middle and rear (touch indices 1, 2 and 3), which are the controller's
channels 2, 1 and 0. A touch reads 1, no touch 0. All three at once trip the
[death switch](https://nao-rs.lukaloehr.com/safety.md). The physical order still needs one touch of each pad
to confirm.

## Checked live

`naoctl head` on the robot: eyes cycling red, green and blue (seen by eye),
24.8 V, 10.7 W, 43 to 47 °C, 5.8 ms per transfer.

## Related topics

- [Hardware reference](https://nao-rs.lukaloehr.com/hardware.md)
- [Chest board link](https://nao-rs.lukaloehr.com/hardware/chest-board.md)
- [Body sensors and units](https://nao-rs.lukaloehr.com/hardware/sensors.md)
- [LEDs](https://nao-rs.lukaloehr.com/hardware/leds.md)
- [Head fan](https://nao-rs.lukaloehr.com/hardware/fan.md)
- Previous: [Body sensors and units](https://nao-rs.lukaloehr.com/hardware/sensors.md)
- Next: [LEDs](https://nao-rs.lukaloehr.com/hardware/leds.md)
