Part 1 of 5 · The foundations

Four small PLCs that switch everything

Tartaruga is our Iveco Daily 4x4 expedition camper. Behind the cupboards and under the floor there is a small industrial control system. This page explains how it is built, why we built it this way, and what it taught us.

Why a PLC in a camper?

Why we chose the Siemens LOGO!

I worked for more than forty years in industrial automation, commissioning plant, much of it with Siemens equipment. That history was not the reason for choosing the LOGO! 8. Forty years of automation also gave me forty years of automation problems. The LOGO! was chosen for one practical reason. It runs directly from a 12 V DC supply, and its inputs and outputs work at 12 V over a wide voltage range. That suits a vehicle.

To be direct: if I had known at the start what I know today about ESP32 microcontrollers, there would be no Siemens LOGO! anywhere in this truck.

The LOGO! is programmed graphically, in what Siemens calls CSF (Control System Flowchart), a function block diagram. Its support for user-defined function blocks is weak. Our complete programme uses only one, a simple latch, which we use mostly for the lights and for local/automatic selections. In my opinion the LOGO! software does not compare well with other IEC 1131 PLC programming standards. It is untidy, difficult to manage as a programme grows, and unpleasant to work with. It also has no compatibility with the Siemens S7 controllers I used during my career.

The hardware is a different story. It has the reliability you expect from the Siemens name, and it has proved that in this truck. During the project, voltage spikes destroyed more than R15 000 of other equipment. The worst event was a failed alternator regulator that put 20 V or more on everything in the camper. The LOGO!s survived all of it. After that event we fitted buck-boost converters in front of every piece of electronics in the truck. They protect the other equipment. The Siemens hardware did not need them.

A LOGO! runs its programme in the same order every cycle and starts the same way every time. Because of this I do not have to search for faults in it at the roadside. Its real value on the road is different: I can change the programme in place, and watch the programme running live while I test the change.

Southern Africa has wide plains that are flat as far as you can see, rolling hills, dunes, and the high, rough mountains of the Drakensberg and the Cape ranges. The roads that cross them are the problem. They are corrugated and full of potholes, and they are often washed away or simply gone. Heat, dust and constant vibration are hard on any electronics.

Over the years Tartaruga has gained a second layer of devices: ESP32 microcontrollers. They read GPS, motion sensors, radar and the truck's own CAN bus, and they drive touchscreens. The PLCs remain the base of the system, and the rest of this series builds on them.

The PLCs switch everything that carries real current. The microcontrollers only make requests.

This rule shapes the whole design. Every pump, contactor, solenoid valve, motor and light is wired to a PLC output. No ESP32 drives a load directly. If a microcontroller stops, restarts or loses its network connection, the PLCs continue to work and the truck stays safe.

All the controllers work together over Modbus TCP. The four PLCs use it to exchange data, and the ESP32 controllers and the WinCC SCADA system on the truck PC use it too. It was the simplest route. When Siemens designed the LOGO!, it seems to have left out the SIMATIC Ethernet protocols, and Modbus TCP is something every device in the truck can use.

Distributed, not centralised

Why four controllers and not one large one

One large PLC in a cupboard would need a cable from every sensor and every load in the vehicle back to that cupboard. A truck body flexes and twists, and every extra metre of wiring is another place where a fault can start. So each controller is mounted next to the equipment it controls. Each one is wired only to its own area, and the four share information over Ethernet.

In the engine bay · truck battery

Engine Bay PLC

Does the minimum of mission-critical work under the bonnet. It is powered from the truck battery, so electrical problems in the camper cannot reach it. It is kept small so that it adds as little load as possible to the truck's starting battery.

  • Exhaust brake, engaged only when the accelerator is released
  • Radiator water flow to the geyser heat exchanger
  • Fuel transfer from the long-range tank, and that tank's level
  • Air pressure, and the compressor that fills the air tank for the exhaust brake
  • Truck battery voltage and current
In the camper

Main Control PLC

The largest programme. It manages power for the living area.

  • Lithium battery bank contactors, including emergency isolation
  • Switching the camper's own 300 A alternator on and off
  • The contactor that joins the camper and truck batteries for starting
  • The DC-DC charger that recharges the truck's starting battery from the camper
  • Solar panels: extend, retract, and series/parallel switching
  • Water pumps, door catches, air horn and transfer case oil cooling pump
Behind the dashboard

Underdash PLC

Everything the driver touches, and the front air suspension.

  • Dash pushbuttons for lights, door and water pump
  • Iveco signals from the body builder plug, through interposing relays: ignition, reverse, headlights, alternator
  • Bullbar and roof spotlights from the headlight stalk
  • Front airbag pressures and their inflate and deflate valves
  • Wind speed and sunlight sensors, and the power supply to the Engine Bay PLC
At the rear

Airbag PLC

Rear air suspension and the camper's own instruments.

  • Rear airbag pressures, valves and the rear compressor
  • Camper battery voltage and current, with energy metering
  • Inclinometer: front-to-back and side-to-side tilt
  • Geyser water temperature, transfer case temperature, water routing valve
  • Awning and back lights, bicycle carrier winch, and the 20 000 lb PTO-driven recovery winch coming
PHOTO TO COME
Main Control PLC cabinet
The Main Control PLC and the battery contactors.
PHOTO TO COME
Engine Bay PLC enclosure
The sealed enclosure in the engine bay.
How they talk

One network, many conversations

Every controller in the truck connects to one small Ethernet network, and they all use the same protocol, Modbus TCP. It is an old industrial protocol, but it is simple and well documented. PLCs, microcontrollers, the SCADA software and our web dashboard can all use it.

The four PLCs also pass measurements to each other. A value is measured once, by the PLC closest to the sensor, and sent to the PLCs that need it. Some examples:

  • The Underdash PLC reads wind speed and sunlight. The Main Control PLC uses them to control the solar panels.
  • The Airbag PLC measures the geyser water temperature. The Engine Bay PLC uses it to control the radiator water changeover solenoids.
  • The Airbag PLC measures the transfer case temperature. The Main Control PLC uses it to run the external oil cooling pump.
  • The Airbag PLC measures the camper battery voltage. The Main Control PLC uses it to manage the batteries and the alternator.
Our server web dashboard · Part 5 The Iveco itself body + engine CAN Router 4G + campsite Wi-Fi Truck PC WinCC SCADA Suspension ESP32 · Part 2 Radar 4 radars · gateway CAN pair 2× ESP32 · Part 4 VEHICLE ETHERNET · MODBUS TCP Engine Bay LOGO! 8 Main Control LOGO! 8 Underdash LOGO! 8 Airbag LOGO! 8 Fridge control coming soon PLCs share measurements · each PLC is wired only to its own area pumps · contactors · solenoid valves · motors · lights · sensors

Drag the drawing or use the arrows to see all of it.

The network has one emergency stop. Pressing it opens the battery contactors and stops the compressors, pumps, door catches and fuel transfer. The PLCs pass the stop signal directly to each other, so it never depends on a microcontroller or a computer.

A day on the road

What the PLCs do in a normal day

Most of the work the PLCs do is not noticed. That is the intention. Here is a normal travel day, seen from the controllers.

Two separate electrical systems. The truck and the camper are two separate electrical systems. The Iveco works with full functionality without any camper PLC, without camper power and without solar. The two systems are joined only when needed.

Starting the engine. The Iveco starting battery has been a problem, so a contactor joins the two systems for engine starting. The contactor stays closed for about 20 minutes after the engine starts, so the starting battery can recover its charge. The driver can also join the systems in an emergency, when extra power is needed. When the ignition comes on, the Underdash PLC also switches on the supply to the Engine Bay PLC, and the network waits a short time to settle before any control logic acts.

Driving. The camper batteries are charged by a separate 300 A aftermarket alternator, not by the Iveco alternator. The Main Control PLC switches it on and off with one digital output, which energises a stand-alone PWM regulator. That regulator holds the alternator at 14.6 V. Radiator water heats the geyser through a heat exchanger. The Engine Bay PLC controls the changeover solenoids from the geyser temperature, and closes them if the water becomes too hot. When the transfer case temperature rises, the Main Control PLC runs its external oil cooling pump. When the main fuel tank is low, one press of a button transfers about 40 litres from the long-range tank. That is half a main tank, which is what it was designed to move.

At camp. In camp mode the Main Control PLC watches wind speed and sunlight. It extends the solar panels when they will produce useful power, and retracts them in bad weather or when there is no benefit. The panels are two layers of panel pairs. The upper pair is always exposed. With the lower panels closed, the two upper panels are connected in series. With the lower panels extended, the wiring changes: on each side the upper and lower panel are in series, and the two sides are in parallel. The panels are different sizes and give different voltages. The solar regulator accepts up to 75 V DC and works best when its input is close to that maximum. So the PLC changes the series/parallel wiring automatically when the panels are half-way out or half-way in. A drawstring encoder measures the panel position.

Looking after the starting battery. This is one of the most important functions in the truck. When the Iveco starting battery drops below 12.45 V, the Engine Bay PLC asks for a battery boost. The Main Control PLC then switches on a DC-DC charger in the camper (see The energy account), which sends power to the truck and charges the starting battery. It does this only when the camper battery voltage is higher than the truck battery voltage. At night it does this only if shore power is connected, so the camper batteries are not drained in the dark. In practice this means the truck battery is charged whenever we are on shore power, or when the solar panels are working and the camper batteries are full. When the charging current stays below 3 A for 5 minutes, the starting battery is full and the request is cancelled. Later the sunlight level will also be part of this decision.

Water pumps start when a tap opens, and run a moment longer so that they do not switch on and off rapidly. After an hour without ignition or shore power, the Engine Bay PLC is switched off so that it does not drain the truck battery.

Tartaruga from above, with the upper solar panel pair on the roof and the lower panel extended over the side of the camper.
Both layers of solar panels deployed. The upper pair stays on the roof; the lower panel slides out over the side.
The driver's seat

The truck PC and SCADA

A small PC in the truck runs Siemens WinCC, the same type of SCADA software used in factory control rooms. The cab screen shows everything the PLCs know: battery voltages and currents, airbag pressures, tank levels, temperatures, and the state of every pump and light. The SCADA can also take manual control. A pump can be forced on, a battery contactor blocked, the alternator switched by hand, or the panels moved by hand when the automatic logic is not the right choice.

The SCADA also decides about remote control. The truck can only be controlled from outside, for example from our web dashboard (Part 5), after remote control has been enabled at the SCADA in the truck. Anyone with access can view the data remotely, but control from outside is a deliberate decision made in the cab.

The same PC does much more than SCADA:

Navigation

OziExplorer with about 99% of the southern African government survey maps on board. Franson GPSGate builds a GPS signal from the NMEA data of the suspension controller, and Garmin nRoute runs live from it. Garmin BaseCamp and MapSource are also installed.

Truck diagnostics

Bosch KTS 540 engine management software, with its diagnostic pod connected to the truck ECU.

Development on the road

LOGO! programming, SCADA development, and the Arduino and ESP32 development environments.

Daily use

Email, web browsing, YouTube and music on the road. Photo storage with cloud access, and video editing and storage.

WinCC overview screen with gauges for diesel level, camper battery voltage, Iveco battery voltage and speed, and status panels for pumps, compressors, airbags and temperatures.
The WinCC overview screen: fuel, both battery systems, speed, wind, sunlight, pumps, compressors and airbag pressures on one page. Tap the image to see it full size. The GPS position is blurred.
Where the ESP32s fit

Adding sensors to the PLCs

A LOGO! switches things reliably. It does not know where it is, it cannot measure the angle of the truck to a fraction of a degree, and it cannot read the Iveco's own computers. The ESP32 controllers do that work, and each has its own page in this series. This is how they connect to the PLCs.

The suspension controller (Part 2) is our main set of instruments. It carries the GPS, a motion sensor, temperature, humidity and air pressure sensors, and the joystick for the airbags. It reads the airbag pressures from the PLCs. We are now completing automatic airbag control while driving. The suspension controller calculates inflate and deflate signals from roll, pitch and yaw. The Airbag PLC receives these automatic commands, decides what to do, and pumps or deflates the rear bags. It sends the same signals to the Underdash PLC, which controls the front bags. The PLCs still open and close every valve, and they still apply their own pressure and time limits, whatever they are asked to do.

The radar controller (Part 3) takes its name from its radar sensors: three fixed to the rear and to the left and right sides of the truck, and a portable battery unit that can stand on the bonnet. They report to the controller over Wi-Fi. They have three jobs:

  • security for the truck, when it is parked and when we are asleep;
  • blind-spot monitoring for the driver;
  • waking us at night when a rare nocturnal animal comes walking through our campsite.

The radar controller also has a large touchscreen in the cab. This screen is a backup for the SCADA: if the truck PC is switched off or not working, we can still see and operate the PLC functions from it. And the radar controller is the gateway between the truck and the Tartaruga web dashboard (Part 5). All dashboard data leaves the truck through it, and dashboard buttons reach the PLCs through it.

Light and solar panel buttons on the touchscreen and on the web dashboard reach the PLCs as requests, in parallel with the physical pushbuttons. Each request must be confirmed every second while the button is held. If the confirmations stop, the request is cancelled within two seconds. A lost connection cannot leave anything running.

The CAN controllers (Part 4) listen to the Iveco's body and engine data buses. Later they will give the PLCs information they have never had, such as the fuel level in the factory tank, engine data and fault codes.

What it taught us

The difficult parts

Very little of this worked the first time. These are some of the lessons.

Protect the electronics from the supply

A failed alternator regulator put 20 V or more on everything in the camper, and voltage spikes during the project destroyed more than R15 000 of equipment. Every piece of electronics now has its own buck-boost converter. All the cab electronics run from the camper's lithium bank through a large converter. A worn converter and one bad supply wire caused screen failures and restarts for weeks before we found them. Many faults that looked like software faults were power faults.

Undocumented memory and shared addresses

At the start of the project, the way the different LOGO! memory areas interact was not documented anywhere. It took a lot of experimenting to find out why analog values were being corrupted by short-lived digital functions, and digital values by analog ones, and to fix it. Later, with PLCs, microcontrollers, the SCADA and a website all reading and writing the same Modbus addresses, two devices could use the same address. A new firmware once used an address that the PLC's solar panel logic already depended on. Now every address is planned and recorded before any code is written.

Everything must fail safe

Every automatic action has a time limit, a pressure limit or a temperature limit, and the PLC itself enforces it. Compressors have duty-cycle limits, valves have a maximum open time, and motors have a maximum run time. Whatever a screen or a website asks for, the PLC will not do anything unsafe.

Standby current matters

When a camper is parked for a week, every device that stays on slowly drains the batteries. Controllers that are not needed switch off, and switch on again with the ignition, shore power or a request from the SCADA.

Still growing

What comes next

The PLC network was built with spare capacity, and that capacity will soon be used.

This page describes the network and how the controllers share the work. The PLC programmes will be described in more detail in a later part.

The series

How the truck thinks