Arduino Due Tips:

On this topic, I would like to share items of lessons learned as well as wisdom I have accumulated on my SAT-TRAC adventure.

1). Board Vin will take 7-20 volts… Suggest you Run 7-8 volts. Regulator chips are not stressed, and the board runs just fine. I set mine to 8V.

2). When using DAC0 and/or DAC1, use 3K 1% resistors on the output. This will protect a vulnerable part of the DUE. Should some circuitry sink or source ~20-30ma to the DACs, the board could be damaged.

3). I found the DAC outputs are not linear when outputting .55 to 2.75v. I had to add an equation to compensate for the voltage output shortfalls. The Due board has the muscle to handle extra manipulation in real-time in my application.

4). I run the ADC in free-running mode. Max samples are 1M Samples per second (SPS)/12 or about 83k SPS for 12 inputs. We will not need that many samples per second. Maybe 10-20 with some additional processes like averaging. As I understand it, it runs independently of the CPU and when we use DMA access, we get the best performance from the DUE. Many analog samples can be taken compared to the slow analogRead() function. My observation is indeed it is fast, and also provides more reliable values.

//ADC startup for all inputs put in set-up area
//Fast ADC access to sample analog inputs multiple times

REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000; //ADC STARTUP to 2/ 21mHz
REG_ADC_MR = (REG_ADC_MR & 0xFFFFFFEF); // LOWRES = 0, dus 12-BIT resolutie
REG_ADC_MR = (REG_ADC_MR & 0x7FFFFFFF); // USEQ = 0, dus normal mode
REG_ADC_MR = (REG_ADC_MR & 0xFF7FFFFF); // ANARCH = 0, dus DIFF0, GAIN0 en OFFSET0
REG_ADC_COR = (REG_ADC_COR & 0x0); // DIFFx = 0 on all channels -> Single ended mode. No offset
ADC->ADC_MR |= 0x80; //set free running mode on ADC
ADC->ADC_CHER = 0x3CFF; // Enable A0 tm A11
delay(1000);

In your loop access the Data like this:

int cntr = 100; // take 100 samples of A0 & A1 real fast — & average

void readAnalogsensor() {
// from DAC on remote: sample cntr times & avg

for (int i = 0; i < cntr; i++) {

while ((ADC->ADC_ISR & 0x3CFF) == 0); // wait for conversion on EOC7
delayMicroseconds(50);
value[1] = ADC->ADC_CDR[6]; //get values in [0-4095] A1
delayMicroseconds(50);
Alg[1] = Alg[1] + value[1];
delayMicroseconds(50);
value[0] = ADC->ADC_CDR[7]; //get values in [0-4095] A0 analog
delayMicroseconds(50);

Alg[0] = Alg[0] + value[0];

}
// Tabulate average Analog values for Analog 0 & 1
for (int i = 0; i < 2; i++) {
AlgAvg[i] = Alg[i] / cntr;
}
// clear out accumulated values
for (int i = 0; i < 2; i++) {
Alg[i] = 0;
}
}

5). Use the Wire.setTimeout(3000); command before issuing the Wire.begin() in the setup. Why? Well anyone who has played with I2C or a.k.a Two-wire, has experienced a sudden intermittent freeze-up requiring a reboot. Well, this fixes that. You will be hard-pressed to find this as common knowledge in the docs. Freeze-ups are usually caused by line noise, or modules not playing well with each other. After you have done everything else to fix the problem to no avail, this works…Big Thank You to Frank at fpaynter.com His article titled “I2C Hangup bug cured! Miracle of Miracles! Film at 11!” offered a solution to the multi-year problem with the I2C freeze situation… He does some really interesting experimentation and documents findings in his blog!

void setup(void)

Wire.setClock(100000L); // set I2C speed

Wire.setTimeout(3000);// reset I2C line on error

Wire.begin();

6). 20×4 LCD displays work on Due. Although soft messages come up in the compiling process. Never fear, power the LCD with 5V, and connect SDA & SCL lines, and everything works. I leave my LCD coding intact and run headless… without the display. Saves ~10-15ma. I use the #include LiquidCrystal_I2C.h library

7). All digital input into the due needs to be clean 0 or 3.3V digital signals. With ripple in most power supplies, you can pass this down to your logic or the due and get inconsistency when sending 1’s or 0’s. I’m using interrupts with my controller. When I do manual commands to move the AZ & EL like On or Off right? Not exactly, the interrupt cycles add their little ditty when it goes on. Keep in mind my finger is on the switch. You would never know it until you put a scope on it or your logic is a little funky. I fixed it by putting 1K resistors on all interface lines and running 2 inverter chips back to back at the remote to make the input to the due picture perfect. Happy Due operation and it works as designed.

8). Use 3.3 Zenors on input and output lines. Should something misbehave, you won’t be buying a new Due board. This has saved my bacon in more than one instance.

9). Use power Diodes like 1N4000 to prevent a reverse polarity situation. Spending too many hours in the shop, you will at times inadvertently reverse the polarity of the power of your project. Should this happen, you will rework/replace/test your buck converters, and need to check anything attached to power. A simple 1N4000 on the incoming powerline will save you lots of grief. Always, monitor the current draw. When Due idles at 140-190ma it is normal. Pulling more means damage needs to be identified. When I create modules like the AS5600 board that uses the TCA9548A multiplexer, I always add a 3.3v Zenor, .1uf, and 220uf cap across the power input for good measures. Also… this is important, note the current draw when it is working correctly. So should something go wrong in the future, you can measure current and isolate the board quickly. Socketing larger ICs is a good idea too!

10). NRF24L01+ 2.4ghz transceivers work fine when powered by the Due’s onboard 3.3v regulator. On HIGH it can pull ~20ma tops. The regulator on the Due can supply a maximum of 800ma. Just don’t load up the onboard regulator with a lot of devices. I have only 1 and don’t forget the 220uf cap across the NRF24L01+ for stability. My ping pong dynamic 1mbps RC link is based on the work of:

/*
Copyright (C) 2011 J. Coliz maniacbug@ymail.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/

With his code and lots of determination, the SAT-TRAC 32 racing at 1Mbps achieves a sub-second response from the remote up to 800m away!

11). When using the AS5600 sensor with the DUE:

  • Some sensors come with a 3mm diametric magnet. I use 6mm diametric magnets and they are attached to 1/4″ or 6.35mm diameter shafts approx 3-5mm away from the sensor… works fine
  • Keep any ferrous metal at least 2-3cm away.
  • For accuracy, you want the sensor to see symmetric magnetic flux. Skew it is not good. I use aluminum brackets, polycarbonate, and nylon hardware for the best results.
  • look at the Serial monitor and codes sent by the sensor. Determine if the magnet is too close or too far. Getting it just right gives excellent results.
  • Protect the sensor power inputs with .1 uf, 220uf caps, and 3.3v Zenor diode. These little buggers are important and don’t tolerate >3.3v well.
  • When using 2 AS5600 sensors, you will need to multiplex due to the fact they have the same hex address. The TCA9548A works very nicely to make it work.
  • The ‘Curious Scientist’ YOUTUBE.com channel did a nice video on the AS5600 & stepper motors. I’ve utilized his code, changed it to accommodate a 2.5:1 ratio, inserted a multiplexer, and ported the 12bit values to DAC0 & DAC1 in real-time. I like the accuracy and the way it works in a wide temperature range.

12). When using multiple 74LVC245 Octal bus transceivers with 3-state outputs, as I’m using, make certain that the bus direction on (#1 A to B) and (#2 A to B) or (#1 B to A) and (#2 B to A) situations are not enabled at the same time. My setup is (#1 A to B) from the CPU and (#2 B to A) from the controller. So when I get #1 A sending signal to the bus while #2 B is sending a signal we will experience higher voltages and current with chip contention which will lead to problems. I know this example can be confusing, and if you have never worked with these chips, you know they have a learning curve. Be careful, cause you will learn these powerful little chips can make your life easier. These chips are 5V tolerant but protecting 3.3v circuitry is important. Use an inverter between the Enable pins so one is on and the other is off… Also, make sure your DIR pins are correct. These chips can drive LEDs or a Logic Level FET with no problem! I use them to route logic when I’m directly connected to the controller or I’m in the RC mode.

13). ITR20001/T IR sensors work great with the DUE:

  • IR LED can be powered by 3.3V — I’m using 330 ohms 1% resistors
  • Use 2n7000 to start up the array, and use your smartphone’s camera to verify a violet glow. Always give them .5 to 1 sec to reach their glory for consistency. Shut them off when not used and save about 10ma per sensor. I’m using 8, so it makes sense.
  • Use a tube to narrow the beam from the IR LED. If you are reading closely spaced binary tables like I am, then you need this narrow. I use 8mm straws cut to a length of 5-6mm and are 3-5mm from the targeted table. If you can find 8mm straws, you can use shrink tubing provided your environment isn’t too hot. My deck radiates up to 150F so I’m using straws.
  • Use a simple algorithm to convert Binary to Decimal. Then use a look-up array to display what the decimal means. From there you could also look up how much time to allocate for the move process. For example, my calibrate system for AZ shows sensors S4, S3, S2, and S1 as 0 1 0 0 or a decimal of 4. In my setup, I have an array that shows 4 is 90 degrees and an associated array determines that it should take 15sec to arrive at zero.

14). Should you need a software reset in your sketch… When I start up my system and go into calibration mode for AZ & EL, I write to an EEPROM the calibration status. Then restart, check the EEPROM and decide to continue calibrating something that timed out or go on to calibrate the EL. The updated AZ & EL EEPROM is referenced and the AS5600s go to 0 AZ, 0 EL. This can come in handy in some situations. CODE: rstc_start_software_reset(RSTC);// That’s it!

15). Install small 3mm LEDs to indicate power on all support modules. They will use about 8-10ma of power, but it is a great help when something is not functioning and maybe a connector to your 3.3 v logic board came loose. Use a 330-470 ohm resistor at 3.3v to minimize the current draw.

16). Use the DUE to program a PWM generator to feed a Dual H-Bridge DC motor controller. Using Serial2 or Serial3, achieve any frequency or duty cycle up to 10Khz & 100% duty effortlessly with the DUE. It’s quiet, efficient, and easy to get that exact control of your azimuth and or elevator mechanisms. Opto-isolated relays will work with 8-bit systems, but utilizing a Due requires you to keep line noise to a minimum. Relays send pulses on the power line which can be tricky for associated modules.

17). Interfacing SATPC32 V. 12.8d to your DUE controller. Probably the #1 challenge to making a system is interfacing the computer to the controller, then #2 the controller to the remote AZEL rotor, and #3 making it do what you want it to do. Big Thanks to Tom Doyle W9KE for the GS232 interface coding. Getting the GS-232 commands parsed was a big help. The connection to the remote via direct or RC is mostly my design but many elements of code come from many talented individuals. Should you need GS232-A protocol, an Arduino sketch in the ARRL publication, Arduino Projects for Ham Radio by Glen Popiel (2017), KW5GP. can be found in chapter 18. Titled “Yaesu Rotator Controller Modification”, Glen does a nice job commenting on his code and it can easily be adapted for your SAT tracker. See the sketch and libraries Here:

18). When using AS5600 chips with the Due, be aware that ferrous metals can skew the AS5600s control magnets flux, as well as motors in the vicinity, which will induce magnetic fields. The SAT-TAC 32 has the capabilities to go 0-360 in 30 seconds. When the DC motors are running a high duty cycle, they emit a strong magnetic flux that will saturate the sensors and lock up the I2C bus. It doesn’t matter if you are running 100k or 400k Samples per sec. (SPS), the chips will lock up. So the tip is, to slow the motors down. The PWM generator needs to run under a 30% duty cycle at 6khz. At this level, you still have good power and torque, and 100% reliability. Satellites can be tracked with a system set to .5 RPM or 1 minute 30 seconds from 0-360 AZ and/or EL. Accurate tracking and 100% reliability is the goal.

19). When you are prototyping your support boards, keep in mind that your remote smart rotor will be in a strong RF & noise environment. Bypass caps need to be added anywhere RF can enter the board. All control lines from the controller use 1k resistors and are bypassed with 2 & 4.7pf caps. Incoming power is bypassed with 100pf and .1uf caps. Supporting boards are outfitted with 2 and, 4.7pf caps as well as 100uf, and .1uf caps on the power rails. DAC0 & DAC1 lines back to the controller are bypassed with 2 & 4.7pf caps which should bypass any 2m & 70cm signals for entering the computer. Use a quality shielded control cable and make sure the shield is grounded properly. Test by putting your rig into 2m & 70cm FM with small amounts of power and hitting the transmit. Are your controller AZ & EL values jumping around? If so, you might need to move the antennas and or triplexer connections around. In my case, I was getting fundamental overloads, as well as excessive motor noise when moving at a strong pace. So I flipped my 2 m antenna to the opposite boom, removed the triplexer off the back, and lowered it. And then I slowed down the motors. Testing with each change and recording the results. I was bouncing 5-10 degrees on transmits and the I2C & Computer would lock up. Now, I get no bounce and 100% reliability. The tip is to be aware that the Due or any other SBC will be sensitive to the environment, RF, and induced noise from line voltage or motors. Put your bypass strategy in now, don’t wait for the issues to present themselves. I’m happy and more accurately relieved to have solved the problems.

20). Develop I2C multiplexer boards for the fastest connection desired. My board was designed to operate at 400khz. Fully bypassed, filtered, and protected with a 3.3v Zenor diode. The board pulls about 5ma at 3.3v! Even with a 3mm LED power-on indicator. If more current is demanded, make certain the wiring is right and you didn’t damage the diode on the build.

21). When running off solar cells, be conscious of power usage. I plan to leave this unit on continuously, so power conservation is important. A lot of the time the system is in idle mode waiting for a bird to make its footprint. Use higher value resistors to limit current when on. Turn off features that are not necessary. For example, the camera and its dedicated power supply consume 300ma @ 12v when it is on. It’s not necessary to run overnight. Also, reduce the power of other features that are one and done like the IR auto-calibrate system. When the system starts up, it goes into a calibration mode and powers 8 IR LEDs and IR detectors. This draw is 80ma. No need to leave them on after a successful calibration, so we shut them off with a small FET switch. All pretty logical considerations…so plan ahead.

This will grow as I think of more tips to pass on… until then 73, Mike