Posted by Rod Ashton on 10/04/2020 11:34:05:
SoD – Sorry lost me a bit there. The original file was given with the Mendel 90 and was a "nophead" download.
As one old duffer to another, could you explain "setup code" and "main code" please?
A simple example may be clearer.
First, an Arduino Uno.
A small microcomputer is mounted on a board the size of a credit-card. The board provides USB access to a PC (where new programs are developed), a power-supply, crystal oscillator clock, and sockets and pins so the user can connect other electronic devices, either reading or writing to them. It also contains a bootloader, allowing existing programs to be replaced with new ones.
A new Arduino does nothing. It has to be programmed to do something useful, such recognising that an input pin (or pins) have changed, and using that information to change the outputs. Input and output relationships can be arbitrarily complex, and involve timers to control a sequence, where the sequence can be altered by the object being controlled. For example, firing a rocket only when the tanks are full and the hoses disconnected:
| WHILE PREPARING_TO_LAUNCH:
| OPEN FUEL_INPUT_VALVE
| OPEN OXYGEN_INPUT_VALVE
| IF FUEL_TANK == FULL and OXYGEN_TANK == FULL
| CLOSE FUEL_VALVE
| CLOSE OXYGEN_VALVE
| DISCONNECT
| IF DISCONNECT_FAILED
| ABORT
| ELSE
| OPEN OXYGEN_OUTPUT_TO_ENGINE
| WAIT 15 SECONDS
| START SPARK_IGNITER
| OPEN FUEL_OUTPUT_TO_ENGINE
When an Arduino is powered up, the bootloader checks to see if a new program is available. If not, it does a bunch of house-keeping needed to set the ball rolling (like activating a Serial USB interface a PC understands), and then starts the user program.
The first part of the user program is in setup(), and it does whatever the user needs to make his program work like allocating pins as inputs or outputs.
When the Arduino IDE opens a new Sketch (Arduino speak for 'program' ), the user gets this screen:
This is a valid program that can be compiled and downloaded onto an Arduino board. As setup() and loop() are empty, it does absolutely nothing. setup() does nothing once. loop() does nothing, very quickly, over and over again, until the power is turned off.
A simple example that does something useful. It blinks the tiny LED marked 'L' top right on the board. It also turns PIn 13 on and off on the adjacent socket. Socket 13 could drive a relay controlling a mains powered lamp, or a klaxon, or whatever.
In the example, pinMode() declares how pin 13 will be used. Setting pin 13 up as an output only needs to be done once, so it's sensible to put the code in setup().
Making the LED blink repeatedly sounds like a job for loop(), and it is. After running setup(), the Arduino calls loop(). Inside loop it finds an instruction telling it make pin 13 HIGH, which is +5V on the Arduino Uno. The next instruction tells the Arduino to wait for 1000 milliseconds before executing the next instruction. Then pin 13 is made LOW, which is 0V. The next instruction is another 1 second delay and loop() finishes.
When loop() exits, the Arduino immediately calls loop() again, and the sequence is repeated. So the LED flashes ON for 1 second, then OFF for 1 second, repeat forever.
A reprap printer follows the same basic sequence, but the code will be much more complicated. Rather than switching a single LED on and off, the Arduino will receive and decode print commands causing it to send streams of pulses to the X,Y and Z motors, setting them forward or reverse, and feeding plastic. Probably also checks temperatures and end-stops to stop printing if anything goes wrong.
I'll search for Mendel 90 and "nophead" to see if I can cast any light on your particular problem.
Dave
Edited By SillyOldDuffer on 10/04/2020 14:44:18