Learn Arduino?

VK3ZYZ

Moderator
Staff member
I have a couple of PCBs coming...
8727BandSelect.jpg

This is a 8 way I2c High Side Driver. It is for the Codan 8727 but also for general use when the screw terminals are fitted.


Arduino7seg.jpg


And a PCB for the 4x7Seg LED display we played with earlier. This should run brighter as there are transistors for switching.
There is plenty of proto area too.
 
Last edited:

VK3ZYZ

Moderator
Staff member
The boards are still in Sydney as far as I can see :(
They have been there for over a week.......

1675216984046.png
 

VK3ZYZ

Moderator
Staff member
I'm still hopeful that the PCBs will arrive in time.
If I've read the SevSeg libraries correctly, the setup for having PNP drivers on the Anodes will be as follows.
It was not really explained well at all.
Code:
void setup() {
  byte numDigits = 4;
  // pins in order to suit the TSB5882 display
             // digits 1, 2, 3, 4 (staring from the left)
  byte digitPins[] = {11,10, 8, 4};
             // segment  a, b, c, d, e, f, g, dp 
  byte segmentPins[] = {13, 7, 9,12, 5, 6, 2, 3};
   
  bool resistorsOnSegments = true; // 'false' means resistors are on digit pins  
/*
    byte hardwareConfig = COMMON_CATHODE;     // = 0 (digitOnVal=LOW,  segmentOnVal = HIGH)
    byte hardwareConfig = COMMON_ANODE;       // = 1 (digitOnVal=HIGH, segmentOnVal = LOW)
    byte hardwareConfig = N_TRANSISTORS;      // = 2 (digitOnVal=HIGH, segmentOnVal = HIGH)
    byte hardwareConfig = P_TRANSISTORS;      // = 3 (digitOnVal=LOW,  segmentOnVal = LOW)
    byte hardwareConfig = NP_COMMON_ANODE;    // = 0 (digitOnVal=LOW,  segmentOnVal = HIGH)
    byte hardwareConfig = NP_COMMON_CATHODE;  // = 1 (digitOnVal=HIGH, segmentOnVal = LOW)
*/
  byte hardwareConfig = P_TRANSISTORS; // PNP transistors on common Anodes. Arduino ports on Cathodes.
  
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected
  
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
  updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(100);
}
 
Last edited:

VK3ZYZ

Moderator
Staff member
This workk to test the 8 way high side driver board, as long as the address is set correctly. For the PCF8574A with link A0 installed, the address is 0x3E.
 

Attachments

Last edited:

VK3ZYZ

Moderator
Staff member
The LED display works :)
SADARC_4x7LED_2_cct.jpg

The PCB has 150R resistors marked but as I did not have any, 220R have been used and the LEDs are bright enough and as a bonus, the didgit current is below the max for the BC557 transistors. Don't use 150R.
 
Last edited:

VK3ZYZ

Moderator
Staff member
The other board, the Codan 8727 Band Select, can be used for a general purpose high side 8 way driver.
Codan8727BandSelect.jpg

Address selection...
1676282430576.png
 
Last edited:

VK3ZYZ

Moderator
Staff member
Here is the data sheet for the MIC2981 chip used in the high side driver board.
It has 8 drivers, each of max 50V at 500mA. The total package current is 3Amps so it is a pretty handy board.
 

Attachments

VK3ZYZ

Moderator
Staff member
NOTE> If you use the PCF8574 chip, the address range is 0x20 to 0x27
If you use the PCF8574A chip, the address range is 0x38 to 0x3F
 

Attachments

VK3ZYZ

Moderator
Staff member
For this coming class, I thought it may be interesting to look at Ultrasonic Distance Sensing.
There are a number of types readily available, the HY-SRF04 with a TX and an RX unit as below. These cost less than $5 in Australia.
There is a SRF05 that looks similar and costs a bit more. I don't have any of those to compare the performance.


Photo on 28-2-23 at 1.51 pm.jpg


These DYP-ME007Y single unit sensors seem to work a lot better but are close to $20 from China.
Photo on 28-2-23 at 1.52 pm.jpg




JSN-SR04T Integrated Ultrasonic Module Distance Measuring Transducer N7K7 below features a fully sealed remote sensor. I have some of these but the magic "somewhere" comes into play!
These are a bit under $20 here from Oz.
1677552925517.png


There is a pretty good explanation of how these work at...
https://arduinogetstarted.com/tutorials/arduino-ultrasonic-sensor and they also publish some example code that we will try out at the lesson.
I'll bring printouts along for you to type in, or you could just download the files from the attached zip.
 

Attachments

VK3ZYZ

Moderator
Staff member
I've just been watching a very good Youtube video to do with these sensors.
This is from the Drone Bot Workshop channel.
His comment about the speed of sound through different mediums was quite good. See if you spot it. I've never thought of Pink Floyd being used to demonstrate a physics property!
 

VK3ZYZ

Moderator
Staff member
Just for interest, here is a video for the waterproof ultrasonic sensors mentioned earlier.
This sensor has some built in smarts and can operate in 5 modes...
1677914941536.png

Watch the video for details.
 
Last edited:

VK3ZYZ

Moderator
Staff member
This gent, Erik Meike, has modified the HC-SR04 sensor...
He taps into the analog out of the sensor...
1678949235180.png

and displays the signal on an OLED display....
1678949589773.png

Here you can see the echos of both his hand and the cardboard box.

I have not tried it as yet but here it is if anyone wants to have a play.
First, I have to install the ADC libs!
Also, this runs on a Teensy board, not a "standard" Nano, so that board will need to be installed too.
I have a Teensy somewhere so I may have a go at this.
 

Attachments

Last edited:

VK3ZYZ

Moderator
Staff member
To make connecting things to your Arduino Uno a little easier, a Sensor Shield, like this one is a good idea.
1680323869047.png

each pin is extended to headers with a gnd and +5V pin.
There are also dedicated connectors for a few, like the analog and the I2C/serial (select able with jumpers).

1680324128887.png

This is a circuit for the board, or at least, something like the one you may get.
A similar shield is available for the Arduino Nanos.
This is but one version...
1680324433829.png


The port pin headers are arranged in the order Gnd-Volts-Signal that suits the connectors on the ends of servo leads.
1680324568014.png
Brown = Gnd.
Red = +5V.
Orange = Signal.
 

VK3ZYZ

Moderator
Staff member
I've started to play with an RTC board.
RTC.jpg

It has a CR2032 cell socket on the back. Also, there is a place for a DS18S30 temperature sensor (of which I have some in stock). Also, an EEPROM.

Photo on 24-4-23 at 3.35 pm.jpg

It is mounted with an extra I2C socket and a pin that makes the square wave out available.

1682317190591.png





Photo on 24-4-23 at 3.36 pm.jpg

1682315434963.png

Code:
#define Version "RTC_Temp_Pot_demo"

#include <RTClib.h>
RTC_DS1307 rtc;

#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4

/* info found by running DS18x20_Temperature from Examples/OneWire
   This will vary between chips.
ROM = 28 86 F1 B6 4 0 0 2B    
  Chip = DS18B20
  Data = 1 87 1 4B 46 7F FF 9 10 48  CRC=48
  Temperature = 24.44 Celsius, 75.99 Fahrenheit
No more addresses.
*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int PotReading      =  0;

// A4 = SDA
// A5 = SCL
#define Pot           A7

// One Wire Bus        4

void setup() {
  // put your setup code here, to run once:
  // automatically sets the RTC to the date & time on PC this sketch was compiled
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  lcd.init();                         // initialize the lcd
  lcd.backlight();
  lcd.print(Version);
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  PotReading=analogRead(Pot);
  lcd.print("Pot=            ");
  lcd.print(PotReading);
  sensors.begin();        // start the Dals one wire

}

void loop() {
  // put your main code here, to run repeatedly:
  DateTime now = rtc.now();
  lcd.setCursor(4,1);         // then position the cursor
  lcd.print(now.hour(), DEC);
  lcd.print(':');
  lcd.print(now.minute(), DEC);
  lcd.print(':');
  lcd.print(now.second(), DEC);
   
    PotReading=analogRead(Pot);   // read the pot
      lcd.setCursor(4,0);         // then position the cursor
      lcd.print("     ");         // erase old reading
      lcd.setCursor(4,0);         // then position the cursor again
      lcd.print(PotReading);      // display new reading

// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
      sensors.requestTemperatures();
      lcd.setCursor(8,0);         // then position the cursor
      lcd.print(" C=      ");         // erase old reading
      lcd.setCursor(11,0);         // then position the cursor again
      lcd.print(sensors.getTempCByIndex(0));      // display new reading

}
Things to add are the ability to set the time, maybe produce an alarm
 
Last edited:

VK3ZYZ

Moderator
Staff member
Some time ago, I watched a Youtube (by Ralph Bacon) video that had a neat hint on how to save space in your code after debugging is complete. So, here is a demo implementation of his idea.
Here is the code I've written following his video ideas.
Code:
#define Version "SerialDebugDemo"
// https://www.youtube.com/watch?v=--KxxMaiwSE

// if DEBUG = 0, there is no Serial used for the debugging.
#define DEBUG 1

#if DEBUG == 1
#define debug(x) Serial.print(x)
#define debugln(x) Serial.println(x)
#else debug(x)
#define debugln(x)
#endif

void setup() {
  Serial.begin(9600);
  debugln("Serial debugging enabled");
  Serial.println(Version);
}

void loop() {
  // put your main code here, to run repeatedly:

}
and the outputs..


Debug off.jpg

Debug on.jpg

This is a very handy trick that I hope I remember to use!


I used to do it this way, with an #if.... #endif for each debug message.

Code:
#define Version "SerialDebugDemoOldWay"
// https://www.youtube.com/watch?v=--KxxMaiwSE

// if DEBUG = 0, there is no Serial used for the debugging.
#define DEBUG 1

void setup() {
  Serial.begin(9600);
#if DEBUG == 1
  { Serial.println("Serial debugging enabled");
  }
#endif  
  Serial.println(Version);
}

void loop() {
  // put your main code here, to run repeatedly:

}

[!CODE]

That is ok for just one but gets messy for lots.
 
Last edited:

VK3ZYZ

Moderator
Staff member
As in the above example, #define is used to make the code easier to work with. Sometimes, the pins need to be redefined after the build, for example, wiring a rotary encoder up reversed. Something I do a lot!!!!
So, here is a way to do that. It was copied from the usdx code example.

Code:
#define VERSION "DefineMods01"

// example of redefining pins. In this example, swapping the pins of an encoder.
// uncomment the following line to swap the pins.

//#define SWAP_ROTARY    1   // Swap rotary direction


#define ROT_A   6         //PD6    (pin 12)
#define ROT_B   7         //PD7    (pin 13)


#ifdef SWAP_ROTARY        // was the encoder wired in reverse?
#undef ROT_A              // yes, undefine the pins
#undef ROT_B
#define ROT_A   7         //PD7    (pin 13) redefine the pins.
#define ROT_B   6         //PD6    (pin 12)
#endif

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}
[!CODE]
 

VK3ZYZ

Moderator
Staff member
The folk at randomnerdtutorials have just published a guide for sensors and modules.

They do havs a lot of good stuff, as I've mentioned before. Some of their guides that they sell are very good value, but they do have a mass of free stuff too.
 
Top