RS-485 Micro-Controller Extension

Based on the conversation from a different topic here in the forum I made a schematic for an extension board that is connected via RS485 and hosts a ATTiny85 micro-controller and can drive 2 PWM signals.

Can someone review the schematic and tell if I’m completely wrong or what needs to be changed to make it working.

The idea is to have the option to have several of these boards connected to the BrewPi and each board will be a slave, the BrewPi the master. For this to work we need to able to address the slave directly, means we need an unique ID for each slave. Should that unique ID be hard coded into the code or should we generate the unique ID on the master or should the slave generate his own unique ID? A salve would never initiate a “conversation”, only master send information and waits for response (successful or fail). How does the master receive all connected UniqueIDs from the boards?

The message the master would be following format:
[Start Byte][Unique ID in x Bytes][PWM# Byte][Command Byte][Param Byte][End Byte]

The message that the slave respond:
[Start Byte][Unique ID in x Bytes][Success Byte][End Byte]

Start and End byte: 0xff
PWM# Byte: will be 0x01 or 0x10
Param Byte : Value between 0x00 and 0xff
Success Byte: 0x00 for fail or 0x01 for success

Commands will be:

  • Set PWM Value
  • Get UniqueID???

Can there be any more command that we will send to the Micro-Controller board?

This is a good start, but I have a couple of thoughts:

  • I am not sure if an attiny is a wise choice, considering the limited code size. For this PWM application, it might be enough, but I have other applications in mind, which ideally would run on the same platform. A cheap ATmega would be a bit more flexible. We could use one that is Arduino compatible for easy prototyping. We would also like to support the following features:

    • Firmware update over RS-485 (via bootloader)
    • Respond to a search command
    • Assign unique ID
  • This application might be write only, but the RS485 protocol should support bidirectional communication. For example a gravity or CO2 sensor. A more flexible addressing scheme and flexible size payload is probably required.

  • There should be CRC checking on communication

  • I would make the outputs open drain, with a 4k7 pullup resistor or have 2 or 3 outputs per channel:

    • Filtered to analog
    • Digital PWM
    • Open drain N-channel mosfet + protection diode
  • It would be great if the board also supported connecting molex PC fans (4 pin). One pin is speed feedback. Driving fans is probably what most people would use this for. I think it would be great to be able to have multiple chambers with fans connecting them and managing temperature.

  • I would use a 4 port connector block like our other extension boards, so you can plug in a couple of temp sensors as well.

That’s my take on how I would approach such a board.For your prototyping, I would just get an Arduino Nano and start working on the protocol and move onto dedicated hardware later.

1 Like

Try SimpleModbus library for arduino. Modbus is the industry standard for a long time and also my default option for PC-Arduino communication.
@Elco since there is an RS-485 port already at BrewPi, do you think that it would be possible to add modbus master functionality at the project?
It would be very useful.
e.g currently I am designing and building a hydrometer. It would be great to be able to attach the RJ11 connector and be able to poll the device.

1 Like