12 sections Machine_USB v5 Arduino nano

Hi, I’m trying to modify the Machine_USB v5_0 code to 12 sections + hydraulic.
I am using Arduino nano. Pins A0-3 work. But I have the impression that agopengps does not send information to machne. Machine_USB_v5_0Mati.ino (8,0 KB)
Sections 9-12 do not work. swapping section 3 with 12 doesn’t work anyway.

Hello, @matias

You are not using the information of the “relayHi” byte after receiving it. “relayLo” just can store 8 bits (sections). Some modification needed in the code:

line 248 add: relayHi = 255 - relayHi;
line 311++ modify:
digitalWrite (9, bitRead(relayHi,0));
digitalWrite (10, bitRead(relayHi,1));
digitalWrite (11, bitRead(relayHi,2));
digitalWrite (12, bitRead(relayHi,3));
digitalWrite (13, bitRead(relayHi,4));

I hope that will work for you. At the moment I have no hardware avaliable to test, but it is compiling without error.

Check pinout of nano, only D1 to D13 and A0 to A7 avaliable. 14, 15, 16 in your code will make problems! Use A0, … instead.

P.S: I would reduce the pinMode setting from line 80 to 95 to a minimum (only real used outputPins) to avoid further problems.

1 Like

Hello again, @matias
Some time ago i have modified this .ino AgOpenGPS/MachineUSB_4310_MEGA16pins_IN_OUT_hagreV3.5.ino at my_Master-old_v4 · hagre/AgOpenGPS · GitHub to work for nano and mega.

If you comment out
//#define INPUT_WITH_SWITCHES_ENABLED in line 35 and set
#define NUM_OF_RELAYS 12
in line 58, and set line 66+ to
//Raise and lower as A0 and A1
#define RAISE_PIN A0
#define LOWER_PIN A1

//Variables for Ralay
#define RELAY0_PIN 2
#define RELAY1_PIN 3
#define RELAY2_PIN 4
#define RELAY3_PIN 5
#define RELAY4_PIN 6
#define RELAY5_PIN 7
#define RELAY6_PIN 8
#define RELAY7_PIN 9

//if MEGA2560 is selected in the arduino IDE to compile
#define RELAY8_PIN 10
#define RELAY9_PIN 11
#define RELAY10_PIN 12
#define RELAY11_PIN 13

this should work for you as well. The code was written for v4.3, please test if the communication with 5.2.2 is still working.

best regards

1 Like

Hello @hagre Dziękuję, że mi pomogłeś. Wszystko zaczęło działać:)