Paul Sutton

Code

Code Club 20/1/2024 Write up

We seem to be heading off at a tangent with code club, however today we carried on with building a robot car, and another group were starting work on a 12 in 1 robot kit.

Elsewhere, we installed Ubuntu on a netbook and had a look at the Sony Laptop, which now dual boots with Ubuntu and has all the various hardware drivers working.

We do however want to get back to coding at Code Club and ensure STEM group is reserved for some of the project work.

Next code club is on 3rd Feb 2024

Tags

#Code,#Coding,#CodeClub,#STEM,#Electronics


MastodonPeertubeQoto sign up

Donate using Liberapay

Code Club 20/1/2024

Usual code club on Saturday 10 – 12 at Paignton Library, we will be in the learning centre for the usual coding activities and in room 10 to carry on with the projects we are doing at the STEM group (see previous post).

Tags

#Code,#Coding,#CodeClub,#STEM,#Electronics


MastodonPeertubeQoto sign up

Donate using Liberapay

Code Club Electronics 12

So the next project is to try and link the potentiometer value to a buzzer tone.

So, using some tutorial code for the buzzer here. I have tried to modify to change the tone of the buzzer depending on the value from the potentiometer.

// the setup function runs once when you press reset or power the board

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
const int buzzer = 5;


void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(buzzer, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  // read the input on analog pin A0:
  int analogValue = analogRead(A0);
  // Rescale to potentiometer's voltage (from 0V to 5V):
  float voltage = floatMap(analogValue, 0, 1023, 0, 5);
  tone(buzzer, 1000);   // 1khz tone to buzzer
  delay(analogValue);                       // wait for time period linked to pot input value
  tone(buzzer, 1000);    // 1khz tone to buzzer

  //https://www.instructables.com/How-to-use-a-Buzzer-Arduino-Tutorial/
}

What I have now is a little buggy, If I bind the actual pot value between 0 and 1023, anything below 20hz is inaudible, so that the frequency is within the human hearing range (20hz – 20khz)

Not quite sure what is going to work, sharing this as work in progress.

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


MastodonPeertubeQoto sign up

Donate using Liberapay

Code Club Electronics 11

I am now combining a LED blink routine, with reading the potentiometer value input.

// the setup function runs once when you press reset or power the board

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}


void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}


  

// the loop function runs over and over again forever
void loop() {
  // read the input on analog pin A0:
  int analogValue = analogRead(A0);
  // Rescale to potentiometer's voltage (from 0V to 5V):
  float voltage = floatMap(analogValue, 0, 1023, 0, 5);
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(analogValue);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(analogValue);                       // wait for a second
}

Video

Video illustrates how rotation of the potentiometer is reflected in the LED blink delay.

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


MastodonPeertubeQoto sign up

Donate using Liberapay

Code Club Electronics 10

So following on from the previous post. Still using the Easy module shield) I have found out how to read the analogue input from the potentiometer. So far this gives a value and voltage.

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-potentiometer
 */

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin A0:
  int analogValue = analogRead(A0);
  // Rescale to potentiometer's voltage (from 0V to 5V):
  float voltage = floatMap(analogValue, 0, 1023, 0, 5);

  // print out the value you read:
  Serial.print("Analog: ");
  Serial.print(analogValue);
  Serial.print(", Voltage: ");
  Serial.println(voltage);
  delay(1000);
}

So the two lines (the first is a comment) sets the program to read from A0

 // read the input on analog pin A0:
  int analogValue = analogRead(A0);

With output looking like

 // read the input on analog pin A0:
  int analogValue = analogRead(A0);

READING THE LIGHT SENSOR

By changing this to

 // read the input on analog pin A1:
  int analogValue = analogRead(A1);

It is possible to read the light sensor on the same board.

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-potentiometer
 */

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin A0:
  int analogValue = analogRead(A0);
  // Rescale to potentiometer's voltage (from 0V to 5V):
  float light = floatMap(analogValue, 0, 1023, 0, 5);

  // print out the value you read:
  Serial.print("Analog: ");
  Serial.print(analogValue);
  Serial.print(", Light: ");
  Serial.println(light);
  delay(1000);
}

I have edited the lines above so that it reflects the fact we are now reading the light sensor.

  float light = floatMap(analogValue, 0, 1023, 0, 5);

  // print out the value you read:
  Serial.print("Analog: ");
  Serial.print(analogValue);
  Serial.print(", Light: ");
  Serial.println(light);
  delay(1000);
}

You will need to change the other lines to suit, as some of the comments still refer to the potentiometer.

Video

Video illustrates how rotation of the potentiometer is reflected in the output values.

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


MastodonPeertubeQoto sign up

Donate using Liberapay

Code Club Electronics 9

So following on from the previous post. I had to look this up to remind myself how to specific a pin.

So my next project, was to try and get the DHT11 temperature and humidity module working. I had a problem with the library for this, so looked at the code, used the section of this that used the LM35 temperature module (which can also be found on the Easy module shield)

float tempC;
int tempPin = 2;
byte temperature = 0;

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{

  tempC = analogRead(tempPin);           //read the value from the sensor
  tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature

  Serial.print("LM35 - Temperature: "); 
  Serial.print((byte)tempC);
  Serial.println(" Celcius");
  delay(500); // delay 5 seconds
}

So just switched to pin 2 above

int tempPin = 2;

And modified the code to give nicer output. The Arduno IDE allows for both plotting of data on a graph and also just using the serial monitor.

Output looks like this

LM35 - Temperature: 18 *C
LM35 - Temperature: 18 *C
LM35 - Temperature: 18 *C

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#TempSensor


MastodonPeertubeQoto sign up

Donate using Liberapay

Code Club Electronics 8

So following on from the previous post. I had to look this up to remind myself how to specific a pin. Not used Arduino in a while. I found the following code as part of a stackoverflow post

However, in this, the two LEDs flash on and off alternately. Delay is set by a single line.

int delayPeriod = 1000;

So this is more so I can learn how to specify a pin.

int ledPin = 12;
int ledPin2 = 13;
int delayPeriod = 1000;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop()
{
  digitalWrite(ledPin, HIGH);
  digitalWrite(ledPin2,LOW);
  delay(delayPeriod);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledPin,LOW);
  delay(delayPeriod);
  //delayPeriod = delayPeriod - 10;
}

In the video, I am just changing a single line of code to cause the delay.

Timings are in milliseconds or seconds

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#LED,#Blink


MastodonPeertubeQoto sign up

Donate using Liberapay

Code Club Electronics 7

Just having a look at an Arduino add-on board, that has various inputs and outputs built in. The following code (from the default IDE library) flashes an LED on and off. The delays can be changed within the code.

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}



// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);                       // wait for 100 milli seconds
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(100);                       // wait for 250 milli seconds
}

The video just shows the last section of code and what happens when the delay is changed.

Timings are in milliseconds or seconds

e.g. 1000 ms = 1 second 2000 ms = 2 seconds 100 ms = 0.1 seconds 250ms = 0.250 seconds (¼ second) 500ms = 0.500 seconds (½ second)

Links

Tags

#Electronics,#Code,#Arduino,#Hacking.#LED,#Blink


MastodonPeertubeQoto sign up

Donate using Liberapay

Raspberry Pi Xmas tree

I was sent a Raspberry Pi xmas tree module last year and have just got round to setting it up. Results with some example code (below) seem pretty good. Most of the LEDs work.

from gpiozero import LEDBoard
from gpiozero.tools import random_values
from signal import pause
tree = LEDBoard(*range(2,28),pwm=True)
for led in tree:
 led.source_delay = 0.1
 led.source = random_values()
pause()

Tags

#RasberryPi,#Python,#Code,#ChristmasTree,


MastodonPeertubeQoto sign up

Donate using Liberapay

Index

Donate using Liberapay

  1. Click on a link.
  2. Scroll to bottom of page.
    • Any posts / pages within this blog will be displayed.

A #AbsorbtionSpectra #Abuse #Academy #Activism #Adenine #Afghanistan #Africa #Alphablocks #AMES #AminoAcid #AmnestyInternational #Analytics #apg #Api #Apt #Aptitude #AralBalkan #Archaeology #Arduino #Artemis #arXiv #AstroBiology #AstroChemistry #Astronify #Astronomy #Astrophysics #AtomicStructure B #bash #BASH #BASHShell #Beamer #better #BibTeX #BigBluButton #BigOil #BioChemistry #Biology #Blender #Blog #Bonfire #Bookworm #Bookwyrm #Browser #Bullseye #Buster C #Castopod #Charity #Chat #Chemistry #Chrome #Chromium #Code #CodeClub #Coding #Commons #Conditions #Conference #Console #Cornwall #Corona #CoronaVirus #Cosmology #Covid19 #cpd #CPD #Creative #CreativeCommons #CreativeEducation #CriticalThinking #CrudeOil #Cryptpad #Crystal #CTAN #CyberSecurity #Cytosine D #DarkMatter #Data #DBS #dcglug #dclug #Debconf #Debian #Decentralised #Decentralized #DeepLearning #Derived #Detox #Development #Devon #Diaspora #Digital #DiodeZone #Discussions #disroot #Disroot #dna #DNA #Docker #Documentation #Donate #Donation #Draft #DRM #Drupal E #Editing #Education #Education #Electronics #Elements #emacs #Email #EmissionSpectra #Employment #Energy #Engine #Ethics #Ethiopia #EventManagement #Events #EveryonesInvited #Exoplanet #Exploration #Exploration F #FalconsEye #Federated #Fediverse #Firefox #Flockingbird #Football #FootBall #Fosdem #FOSSandCrafts #FossileFuels #Foundation #Framablog #FramaBlog #Framework #FreeBSD #FreeBSD #Freedom #FreeSoftware #Friendica #Friendica #FSF #FSFE #Funkwhale #Fusion #FutureLearn G #Galaxy #Galculator #Games #Gamma #GDPR #GettingStarted #Ghostreply #Gimp #Git #Gitlab #GitLab #gm #GNOME #GNU #GnuSocial #GoAccess #GoatCounter #GoDot #gold #GPL #GraphicsMagick #Greek #Guanine #GUI H #Hack #Hacking #Hardware #Hexchat #HomeChemistry #HomeChemistry1 #HomeChemistry10 #HomeChemistry11 #HomeChemistry12 #HomeChemistry13 #HomeChemistry14 #HomeChemistry15 #HomeChemistry16 #HomeChemistry17 #HomeChemistry18 #HomeChemistry2 #HomeChemistry3 #HomeChemistry4 #HomeChemistry5 #HomeChemistry6 #HomeChemistry7 #HomeChemistry8 #HomeChemistry9 #Hosting #htop #Hubble #Hubzilla #HumanRights #Hypothesis I #Image #ImageManipulation #Index #InfoGraphic #information #Inkscape #Invidious #IRC J #JamesWebb #Jit.si #Jitsi #JoeEditor #jpl #JPL #Jupyter #JupyterNotebook #JWST K #Kanban #kbin #KCSIE #KDE #KeepingChildrenSafeinEducation, #Kenya #kstars L #LaTeX #Law #Learning #Lecture #Legal #Legislation #Lemmy #LGPL #LiberaPay #Libre #LibreAdventure #LibreLounge #Librem #Libreoffice #LibreOffice #LibreOfficeCalc #LibreOfficeDraw #LibreOfficeGettingStarted #LibreOfficeImpres #LibreOfficeWriter #LibrePlanet #Linux #LinuxMint #LXDE #Lynx M #Magnesium #Management #Manganese #Map #Mapscii #Mars #Mastodon #Materials #Matomo #Matrix #Maya #Meeting #Meetings #mercury #Mercury #Meta #Micro.blog #mining #Misskey #mobile #Mobile #Mobilizon #Mobilizon #MolarSolutionCalculator #Moon N #NaCl #Nano #NationsLeague #Nebula #NetHack #network #NewSkillsAcademy #Nextcloud #NFL #NGINX #Nuclear #NuclearFusion #Nucleobases O #Oil #OilProducts #Online #Online #OnlineSafetyBill #Open #OpenData #OpenLearn #OpenStreetMap #OpenUniversity #Orbitals #OU #Overleaf #Owncast #OwnCloud P #Package #PaigntonLibrarySTEMGroup #Pandas #Paper #ParticlePhysics #Particles #Password #Payment #Paypal #PDF #PeerTube #PeriodicTable #Phonics #Photo #Photograph #Photographs #Photos #Physics #pinebook #pinephone #PixelFed #Planet #Plausible #Pleroma #Plume #Podcast #PowderToy #Privacy #Production #Products #Programming #ProtoSchool #Public #Purism #Python #Python3 Q #Quark #Quarks R #RadioAstronomy #Reading #Recovery #RedBubble #Research #Rights #rna #RNA #RocksAndDiamonds #Rookie #RookieCamp #RedCabbage S #Safeguarding #Safety #Salt #Schools #Science #ScienceDaily #Scismic #Scratch #Scratch2 #Scratch3 #SDTJ #Seagl #Security #Simulator #Sitejs #Skymaps #smallweb #Soccer #Social #SocialHome #SocialHub #SodiumChloride #Solarus #Solid #SouthDevonTechJam #Space #Stars #Stellarium #Stickers #Stripe #stsci #Symmetry #Synaptic T #Tailings #Talk #Teaching #TeachingAssistant #Techlearningcollective #Telescope #Terminal #Terms #TeX #TextEditor #TheOpenUniversity #Theory #TheOU #Thesis #Thunar #Thunderbird #Thymine #Tilde #Toot #Top #Topic #Torbay #TorbayTrojans #Transit #Translation #Trojans #Trunk #Tuxiversity U #Ulytsheavy #Umami #UN #UnitedKingdom #UnitedNations #UniverseOfLearning #Uracil #Use #users V #Vaccine #Virgo #VLC #VokoScreen #Volunteer #Volunteering #VultureNethack #vultureseye W #wayland #weatherinfo #Website #wicd #wireless #Wordpress #Work #WorldCup #WorldSpaceWeek #Wormhole #Write.as #Write freely #Writing #WhiteVinegar X #Xchat #XenonLamp #XFCE #XFCE4 #XMPP #xorg #Xournal #xray Y #YearOfTheFediverse Z #Zoo