Control Panel

Pic School + Arduino Mega

/*
 * Arduino Keypad calculator Program
 */

#include <LiquidCrystal.h> //Header file for LCD from https://www.arduino.cc/en/Reference/LiquidCrystal
#include <Keypad.h> //Header file for Keypad from https://github.com/Chris--A/Keypad

const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns

// Define the Keymap
char keys[ROWS][COLS] = {

  {'1','2','3','A'},

  {'4','5','6','B'},

  {'7','8','9','C'},

  {'*','0','#','D'}

};

int pinArray[] = {2, 3, 4, 5, 6, 7};
int count = 0;
int timer = 75;
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 10;     // the number of the pushbutton pin
// variables will change:
int buttonState = 0; 

byte rowPins[ROWS] = { 33, 31, 29, 27 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 41, 39, 37, 35 }; // Connect keypad COL0, COL1 and COL2 to these Arduino pins.

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //  Create the Keypad

const int rs = 43, en = 45, d4 = 47, d5 = 49, d6 = 51, d7 = 53; //Pins to which LCD is connected
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

 long Num1,Num2,Number;
 char key,action;
 boolean result = false;
 
void setup() {
  // we make all the declarations at once
  for (count=0;count<6;count++) {
    pinMode(pinArray[count], OUTPUT);
  }
  lcd.begin(16, 2); //We are using a 16*2 LCD display
  lcd.print("Ona's Calculator"); //Display a intro message
  lcd.setCursor(0, 1);   // set the cursor to column 0, line 1
  lcd.print("-V1.0"); //Display a intro message 

   delay(2000); //Wait for display to show info
    lcd.clear(); //Then clean it
}

void loop() {
buttonState = digitalRead(buttonPin);
key = kpd.getKey(); //storing pressed key value in a char

if (buttonState == HIGH) 
KnightRider();

if (key!=NO_KEY)
DetectButtons();

if (result==true)
CalculateResult();

DisplayResult();   
}

void DetectButtons()
{ 
     lcd.clear(); //Then clean it
    if (key=='*') //If cancel Button is pressed
    {Serial.println ("Button Cancel"); Number=Num1=Num2=0; result=false;}
    
     if (key == '1') //If Button 1 is pressed
    {Serial.println ("Button 1"); 
    if (Number==0)
    Number=1;
    else
    Number = (Number*10) + 1; //Pressed twice
    }
    
     if (key == '4') //If Button 4 is pressed
    {Serial.println ("Button 4"); 
    if (Number==0)
    Number=4;
    else
    Number = (Number*10) + 4; //Pressed twice
    }
    
     if (key == '7') //If Button 7 is pressed
    {Serial.println ("Button 7");
    if (Number==0)
    Number=7;
    else
    Number = (Number*10) + 7; //Pressed twice
    } 
  

    if (key == '0')
    {Serial.println ("Button 0"); //Button 0 is Pressed
    if (Number==0)
    Number=0;
    else
    Number = (Number*10) + 0; //Pressed twice
    }
    
     if (key == '2') //Button 2 is Pressed
    {Serial.println ("Button 2"); 
     if (Number==0)
    Number=2;
    else
    Number = (Number*10) + 2; //Pressed twice
    }
    
     if (key == '5')
    {Serial.println ("Button 5"); 
     if (Number==0)
    Number=5;
    else
    Number = (Number*10) + 5; //Pressed twice
    }
    
     if (key == '8')
    {Serial.println ("Button 8"); 
     if (Number==0)
    Number=8;
    else
    Number = (Number*10) + 8; //Pressed twice
    }   
  

    if (key == '#')
    {Serial.println ("Button Equal"); 
    Num2=Number;
    result = true;
    }
    
     if (key == '3')
    {Serial.println ("Button 3"); 
     if (Number==0)
    Number=3;
    else
    Number = (Number*10) + 3; //Pressed twice
    }
    
     if (key == '6')
    {Serial.println ("Button 6"); 
    if (Number==0)
    Number=6;
    else
    Number = (Number*10) + 6; //Pressed twice
    }
    
     if (key == '9')
    {Serial.println ("Button 9");
    if (Number==0)
    Number=9;
    else
    Number = (Number*10) + 9; //Pressed twice
    }  

      if (key == 'A' || key == 'B' || key == 'C' || key == 'D') //Detecting Buttons on Column 4
  {
    Num1 = Number;    
    Number =0;
    if (key == 'A')
    {Serial.println ("Addition"); action = '+';}
     if (key == 'B')
    {Serial.println ("Subtraction"); action = '-'; }
     if (key == 'C')
    {Serial.println ("Multiplication"); action = '*';}
     if (key == 'D')
    {Serial.println ("Devesion"); action = '/';}  

    delay(100);
  }
  
}

void CalculateResult()
{
  if (action=='+')
    Number = Num1+Num2;

  if (action=='-')
    Number = Num1-Num2;

  if (action=='*')
    Number = Num1*Num2;

  if (action=='/')
    Number = Num1/Num2; 
}

void DisplayResult()
{
  lcd.setCursor(0, 0);   // set the cursor to column 0, line 1
  lcd.print(Num1); lcd.print(action); lcd.print(Num2); 
  
  if (result==true)
  {lcd.print(" ="); lcd.print(Number);} //Display the result
  
  lcd.setCursor(0, 1);   // set the cursor to column 0, line 1
  lcd.print(Number); //Display the result
}

void KnightRider(){
  for (count=0;count<7;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   
  }
  for (count=6;count>=0;count--) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   
  }
}

Setting up two-factor authentication on your Raspberry Pi

Enabling two-factor authentication (2FA) to boost security for your important accounts is becoming a lot more common these days. However you might be surprised to learn that you can do the same with your Raspberry Pi. You can enable 2FA on Raspberry Pi, and afterwards you’ll be challenged for a verification code when you access it remotely via Secure Shell (SSH).

Accessing your Raspberry Pi via SSH

A lot of people use a Raspberry Pi at home as a file, or media, server. This is has become rather common with the launch of Raspberry Pi 4, which has both USB 3 and Gigabit Ethernet. However, when you’re setting up this sort of server you often want to run it “headless”; without a monitor, keyboard, or mouse. This is especially true if you intend tuck your Raspberry Pi away behind your television, or somewhere else out of the way. In any case, it means that you are going to need to enable Secure Shell (SSH) for remote access.

However, it’s also pretty common to set up your server so that you can access your files when you’re away from home, making your Raspberry Pi accessible from the Internet.

Most of us aren’t going to be out of the house much for a while yet, but if you’re taking the time right now to build a file server, you might want to think about adding some extra security. Especially if you intend to make the server accessible from the Internet, you probably want to enable two-factor authentication (2FA) using Time-based One-Time Password (TOTP).

What is two-factor authentication?

Two-factor authentication is an extra layer of protection. As well as a password, “something you know,” you’ll need another piece of information to log in. This second factor will be based either on “something you have,” like a smart phone, or on “something you are,” like biometric information.

We’re going to go ahead and set up “something you have,” and use your smart phone as the second factor to protect your Raspberry Pi.

Updating the operating system

The first thing you should do is make sure your Raspberry Pi is up to date with the latest version of Raspbian. If you’re running a relatively recent version of the operating system you can do that from the command line:

$ sudo apt-get update
$ sudo apt-get full-upgrade

If you’re pulling your Raspberry Pi out of a drawer for the first time in a while, though, you might want to go as far as to install a new copy of Raspbian using the new Raspberry Pi Imager, so you know you’re working from a good image.

Enabling Secure Shell

The Raspbian operating system has the SSH server disabled on boot. However, since we’re intending to run the board without a monitor or keyboard, we need to enable it if we want to be able to SSH into our Raspberry Pi.

The easiest way to enable SSH is from the desktop. Go to the Raspbian menu and select “Preferences > Raspberry Pi Configuration”. Next, select the “Interfaces” tab and click on the radio button to enable SSH, then hit “OK.”

You can also enable it from the command line using systemctl:

$ sudo systemctl enable ssh
$ sudo systemctl start ssh

Alternatively, you can enable SSH using raspi-config, or, if you’re installing the operating system for the first time, you can enable SSH as you burn your SD Card.

Enabling challenge-response

Next, we need to tell the SSH daemon to enable “challenge-response” passwords. Go ahead and open the SSH config file:

$ sudo nano /etc/ssh/sshd_config

Enable challenge response by changing ChallengeResponseAuthentication from the default no to yes.

Editing /etc/ssh/ssd_config.

Then restart the SSH daemon:

$ sudo systemctl restart ssh

It’s good idea to open up a terminal on your laptop and make sure you can still SSH into your Raspberry Pi at this point — although you won’t be prompted for a 2FA code quite yet. It’s sensible to check that everything still works at this stage.

Installing two-factor authentication

The first thing you need to do is download an app to your phone that will generate the TOTP. One of the most commonly used is Google Authenticator. It’s available for Android, iOS, and Blackberry, and there is even an open source version of the app available on GitHub.

Google Authenticator in the App Store.

So go ahead and install Google Authenticator, or another 2FA app like Authy, on your phone. Afterwards, install the Google Authenticator PAM module on your Raspberry Pi:

$ sudo apt install libpam-google-authenticator

Now we have 2FA installed on both our phone, and our Raspberry Pi, we’re ready to get things configured.

Configuring two-factor authentication

You should now run Google Authenticator from the command line — without using sudo — on your Raspberry Pi in order to generate a QR code:

$ google-authenticator

Afterwards you’re probably going to have to resize the Terminal window so that the QR code is rendered correctly. Unfortunately, it’s just slightly wider than the standard 80 characters across.

The QR code generated by google-authenticator. Don’t worry, this isn’t the QR code for my key; I generated one just for this post that I didn’t use.

Don’t move forward quite yet! Before you do anything else you should copy the emergency codes and put them somewhere safe.

These codes will let you access your Raspberry Pi — and turn off 2FA — if you lose your phone. Without them, you won’t be able to SSH into your Raspberry Pi if you lose or break the device you’re using to authenticate.

Next, before we continue with Google Authenticator on the Raspberry Pi, open the Google Authenticator app on your phone and tap the plus sign (+) at the top right, then tap on “Scan barcode.”

Your phone will ask you whether you want to allow the app access to your camera; you should say “Yes.” The camera view will open. Position the barcode squarely in the green box on the screen.

Scanning the QR code with the Google Authenticator app.

As soon as your phone app recognises the QR code it will add your new account, and it will start generating TOTP codes automatically.

The TOTP in Google Authenticator app.

Your phone will generate a new one-time password every thirty seconds. However, this code isn’t going to be all that useful until we finish what we were doing on your Raspberry Pi. Switch back to your terminal window and answer “Y” when asked whether Google Authenticator should update your .google_authenticator file.

Then answer “Y” to disallow multiple uses of the same authentication token, “N” to increasing the time skew window, and “Y” to rate limiting in order to protect against brute-force attacks.

You’re done here. Now all we have to do is enable 2FA.

Enabling two-factor authentication

We’re going to use Linux Pluggable Authentication Modules (PAM), which provides dynamic authentication support for applications and services, to add 2FA to SSH on Raspberry Pi.

Now we need to configure PAM to add 2FA:

$ sudo nano /etc/pam.d/sshd

Add auth required pam_google_authenticator.so to the top of the file. You can do this either above or below the line that says @include common-auth.

Editing /etc/pam.d/sshd.

As I prefer to be prompted for my verification code after entering my password, I’ve added this line after the @include line. If you want to be prompted for the code before entering your password you should add it before the @include line.

Now restart the SSH daemon:

$ sudo systemctl restart ssh

Next, open up a terminal window on your laptop and try and SSH into your Raspberry Pi.

Wrapping things up

If everything has gone to plan, when you SSH into the Raspberry Pi, you should be prompted for a TOTP after being prompted for your password.

SSH’ing into my Raspberry Pi.

You should go ahead and open Google Authenticator on your phone, and enter the six-digit code when prompted. Then you should be logged into your Raspberry Pi as normal.

You’ll now need your phone, and a TOTP, every time you ssh into, or scp to and from, your Raspberry Pi. But because of that, you’ve just given a huge boost to the security of your device.

Now you have the Google Authenticator app on your phone, you should probably start enabling 2FA for your important services and sites — like Google, Twitter, Amazon, and others — since most bigger sites, and many smaller ones, now support two-factor authentication.

The post Setting up two-factor authentication on your Raspberry Pi appeared first on Raspberry Pi.

Noticia Original

7 Segmentos 4 digitos

Código para mostrar 7Seg

// Pin 2-8 is connected to the 7 segments of the display.

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int D1 = 9;
int D2 = 10;
int D3 = 11;
int D4 = 12;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pins as outputs.
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {

// THIS MOVES BELOW CODE TO THE NEXT LCD BLOCK
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
digitalWrite(D3, LOW);
digitalWrite(D4, LOW);
//THIS ENDS THE MOVEMENT AND REMAINS ON THE LAST BLOCK FOR THE FOLLOWING DIGITS

//0
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, HIGH);
delay(1000); // wait for a second

// THIS MOVES BELOW CODE TO THE NEXT LCD BLOCK
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
digitalWrite(D3, LOW);
digitalWrite(D4, LOW);
//THIS ENDS THE MOVEMENT AND REMAINS ON THE LAST BLOCK FOR THE FOLLOWING DIGITS

//1
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
delay(1000); // wait for a second

// THIS MOVES BELOW CODE TO THE NEXT LCD BLOCK
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
digitalWrite(D3, HIGH);
digitalWrite(D4, LOW);
//THIS ENDS THE MOVEMENT AND REMAINS ON THE LAST BLOCK FOR THE FOLLOWING DIGITS

//2
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, HIGH);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

// THIS MOVES BELOW CODE TO THE NEXT LCD BLOCK
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
digitalWrite(D3, LOW);
digitalWrite(D4, HIGH);
//THIS ENDS THE MOVEMENT AND REMAINS ON THE LAST BLOCK FOR THE FOLLOWING DIGITS

//3
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//4
digitalWrite(pinA, HIGH);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//5
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//6
digitalWrite(pinA, LOW);
digitalWrite(pinB, HIGH);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//7
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, HIGH);
digitalWrite(pinG, HIGH);
delay(1000); // wait for a second

//8
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, LOW);
digitalWrite(pinE, LOW);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

//9
digitalWrite(pinA, LOW);
digitalWrite(pinB, LOW);
digitalWrite(pinC, LOW);
digitalWrite(pinD, HIGH);
digitalWrite(pinE, HIGH);
digitalWrite(pinF, LOW);
digitalWrite(pinG, LOW);
delay(1000); // wait for a second

}
// Pin 2-8 is connected to the 7 segments of the display.
/*
int segA = 2; 
int segB = 3; 
int segC = 4; 
int segD = 5; 
int segE = A0; //pin 6 is used bij display 1 for its pwm function
int segF = 7; 
int segG = 8; 
int digit1 = 6; //PWM Display most left display
int digit2 = 9; //PWM Display second left
int digit3 = 10; //PWM Display second right display
int digit4 = 11; //PWM Display most right display
*/


int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = A0; //6
int pinF = 7;
int pinG = 8;
int D1 = 6;
int D2 = 9;
int D3 = 10;
int D4 = 11;
//general var

long incomingByte;

#define DISPLAY_BRIGHTNESS  500

boolean duiz = false;
boolean hon = false;

// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
// initialize the digital pins as outputs.
pinMode(pinA, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinC, OUTPUT);
pinMode(pinD, OUTPUT);
pinMode(pinE, OUTPUT);
pinMode(pinF, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  //  incomingByte = random(1000, 9999);
  Serial.println(incomingByte);
 
    duiz = false;
    hon = false;
       for(int k = 0; k<10; k++){ // for loop to slow it down.
    incomingByte=42;    
       
for(int digit = 1 ; digit < 5 ; digit++) {
    switch(digit){
        case 1:
            if (incomingByte>999) {
                digitalWrite(D1, HIGH);
                showNumber(incomingByte /1000);
                incomingByte %= 1000;
                
                delayMicroseconds(DISPLAY_BRIGHTNESS); 
             if (incomingByte < 100){
            duiz = true;
            if (incomingByte <10){
            hon = true;
         }
     
      }else duiz = false; 
     }
            break;
        case 2:
            if (duiz==true){
              digitalWrite(D2, HIGH);
                showNumber(0);
                delayMicroseconds(DISPLAY_BRIGHTNESS); 
              }
               if(hon == true){
            break;
            }
            if (incomingByte>99 && incomingByte<1000) {
                digitalWrite(D2, HIGH);
                showNumber(incomingByte /100);
                incomingByte %= 100;
                delayMicroseconds(DISPLAY_BRIGHTNESS); 
                if (incomingByte < 10){
                  hon = true;
                }else hon = false;
            }
            break;
        case 3:
         if (hon==true){
              digitalWrite(D3, HIGH);
                showNumber(0);
                delayMicroseconds(DISPLAY_BRIGHTNESS); 
                break;
              }
                       
            if (incomingByte>9 && incomingByte<100) {
                digitalWrite(D3, HIGH);
                showNumber(incomingByte /10);
                incomingByte %= 10;
                delayMicroseconds(DISPLAY_BRIGHTNESS); 
            }
            break;
         case 4:
            if (incomingByte < 10) {
                digitalWrite(D4, HIGH);
                showNumber(incomingByte);
                delayMicroseconds(DISPLAY_BRIGHTNESS); 
            }
            break;
   

    } 
showNumber(11);
//ALL DIGITS OFF
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
digitalWrite(D3, LOW);
digitalWrite(D4, LOW);
}
}}

void showNumber(int numToDisplay) {
switch (numToDisplay){
  case 0:
  //0
      digitalWrite(pinA, LOW);
      digitalWrite(pinB, LOW);
      digitalWrite(pinC, LOW);
      digitalWrite(pinD, LOW);
      digitalWrite(pinE, LOW);
      digitalWrite(pinF, LOW);
      digitalWrite(pinG, HIGH);
      break;
  case 1:
      //1
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        break;

    case 2:
        //2
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
        break;

    case 3:
        //3
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
        break;

    case 4:
        //4
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
        break;
    case 5: 
            //5
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
        break;
    case 6: 
        //6
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
        break;
    case 7: 
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        break;
    case 8:
        //8
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
        break;
    case 9:
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, LOW);
        break;

}
}

Help medical research with folding@home

Did you know: the first machine to break the exaflop barrier (one quintillion floating‑point operations per second) wasn’t a huge dedicated IBM supercomputer, but a bunch of interconnected PCs with ordinary CPUs and gaming GPUs.

With that in mind, welcome to the Folding@home project, which is targeting its enormous power at COVID-19 research. It’s effectively the world’s fastest supercomputer, and your PC can be a part of it.

COVID-19

The Folding@home project is now targeting COVID-19 research

Folding@home with Custom PC

Put simply, Folding@home runs hugely complicated simulations of protein molecules for medical research. They would usually take hundreds of years for a typical computer to process. However, by breaking them up into smaller work units, and farming them out to thousands of independent machines on the Internet, it’s possible to run simulations that would be impossible to run experimentally.

Back in 2004, Custom PC magazine started its own Folding@home team. The team is currently sitting at number 12 on the world leaderboard and we’re still going strong. If you have a PC, you can join us (or indeed any Folding@home team) and put your spare clock cycles towards COVID-19 research.

Get folding

Getting your machine folding is simple. First, download the client. Your username can be whatever you like, and you’ll need to put in team number 35947 to fold for the Custom PC & bit-tech team. If you want your PC to work on COVID-19 research, select ‘COVID-19’ in the ‘I support research finding’ pulldown menu.

Set your username and team number

Enter team number 35947 to fold for the Custom PC & bit-tech team

You’ll get the most points per Watt from GPU folding, but your CPU can also perform valuable research that can’t be done on your GPU. ‘There are actually some things we can do on CPUs that we can’t do on GPUs,’ said Professor Greg Bowman, Director of Folding@home, speaking to Custom PC in the latest issue.

‘With the current pandemic in mind, one of the things we’re doing is what are called “free energy calculations”. We’re simulating proteins with small molecules that we think might be useful starting points for developing therapeutics, for example.’

Select COVID-19 from the pulldown menu

If you want your PC to work on COVID-19 research, select ‘COVID-19’ in the ‘I support research finding’ pulldown menu

Bear in mind that enabling folding on your machine will increase power consumption. For reference, we set up folding on a Ryzen 7 2700X rig with a GeForce GTX 1070 Ti. The machine consumes around 70W when idle. That figure increases to 214W when folding on the CPU and around 320W when folding on the GPU as well. If you fold a lot, you’ll see an increase in your electricity bill, so keep an eye on it.

Folding on Arm?

Could we also see Folding@home running on Arm machines, such as Raspberry Pi? ‘Oh I would love to have Folding@home running on Arm,’ says Bowman. ‘I mean they’re used in Raspberry Pis and lots of phones, so I think this would be a great future direction. We’re actually in contact with some folks to explore getting Folding@home running on Arm in the near future.’

In the meantime, you can still recruit your Raspberry Pi for the cause by participating in Rosetta@home, a similar project also working to help the fight against COVID-19. For more information, visit the Rosetta@home website.

You’ll also find a full feature about Folding@home and its COVID-19 research in Issue 202 of Custom PC, available from the Raspberry Pi Press online store.

The post Help medical research with folding@home appeared first on Raspberry Pi.

Noticia Original

Making the best of it: online learning and remote teaching

As many educators across the world are currently faced with implementing some form of remote teaching during school closures, we thought this topic was ideal for the very first of our seminar series about computing education research.

Image by Mudassar Iqbal from Pixabay

Research into online learning and remote teaching

At the Raspberry Pi Foundation, we are hosting a free online seminar every second Tuesday to explore a wide variety of topics in the area of digital and computing education. Last Tuesday we were delighted to welcome Dr Lauren Margulieux, Assistant Professor of Learning Sciences at Georgia State University, USA. She shared her findings about different remote teaching approaches and practical tips for educators in the current crisis.

Lauren’s research interests are in educational technology and online learning, particularly for computing education. She focuses on designing instructions in a way that supports online students who do not necessarily have immediate access to a teacher or instructor to ask questions or overcome problem-solving impasses.

A vocabulary for online and blended learning

In non-pandemic situations, online instruction comes in many forms to serve many purposes, both in higher education and in K-12 (primary and secondary school). Much research has been carried out in how online learning can be used for successful learning outcomes, and in particular, how it can be blended with face-to-face (hybrid learning) to maximise the impact of both contexts.

In her seminar talk, Lauren helped us to understand the different ways in which online learning can take place, by sharing with us vocabulary to better describe different ways of learning with and through technology.

Lauren presented a taxonomy for classifying types of online and blended teaching and learning in two dimensions (shown in the image below). These are delivery type (technology or instructor), and whether content is received by learners, or actually being applied in the learning experience.

Lauren Margulieux seminar slide showing her taxonomy for different types of mixed student instruction

In Lauren’s words: “The taxonomy represents the four things that we control as instructors. We can’t control whether our students talk to each other or email each other, or ask each other questions […], therefore this taxonomy gives us a tool for defining how we design our classes.”

This taxonomy illustrates that there are a number of different ways in which the four types of instruction — instructor-transmitted, instructor-mediated, technology-transmitted, and technology-mediated — can be combined in a learning experience that uses both online and face-to-face elements.

Using her taxonomy in an examination (meta-analysis) of 49 studies relating to computer science teaching in higher education, Lauren found a range of different ways of mixing instruction, which are shown in the graph below.

  • Lecture hybrid means that the teaching is all delivered by the teacher, partly face-to-face and partly online.
  • Practice hybrid means that the learning is done through application of content and receiving feedback, which happens partly face-to-face or synchronously and partly online or asynchronously.
  • Replacement blend refers to instruction where lecture and practice takes place in a classroom and part of both is replaced with an online element.
  • Flipped blend instruction is where the content is transmitted through the use of technology, and the application of the learning is supported through an instructor. Again, the latter element can also take place online, but it is synchronous rather than asynchronous — as is the case in our current context.
  • Supplemental blend learning refers to instruction where content is delivered face-to-face, and then practice and application of content, together with feedback, takes place online — basically the opposite of the flipped blend approach.

Lauren Margulieux seminar slide showing learning outcomes of different types of mixed student instruction

Lauren’s examination found that the flipped blend approach was most likely to demonstrate improved learning outcomes. This is a useful finding for the many schools (and universities) that are experimenting with a range of different approaches to remote teaching.

Another finding of Lauren’s study was that approaches that involve the giving of feedback promoted improved learning. This has also been found in studies of assessment for learning, most notably by Black and Wiliam. As Lauren pointed out, the implication is that the reason blended and flipped learning approaches are the most impactful is that they include face-to-face or synchronous time for the educator to discuss learning with the students, including giving feedback.

Lauren’s tips for remote teaching

Of course we currently find ourselves in the midst of school closures across the world, so our only option in these circumstances is to teach online. In her seminar talk, Lauren also included some tips from her own experience to help educators trying to support their students during the current crisis:

  • Align learning objectives, instruction, activities, assignments, and assessments.
  • Use good equipment: headphones to avoid echo and a good microphone to improve clarity and reduce background noise.
  • Be consistent in disseminating information, as there is a higher barrier to asking questions.
  • Highlight important points verbally and visually.
  • Create ways for students to talk with each other, through discussions, breakout rooms, opportunities to talk when you aren’t present, etc.
  • Use video when possible while talking with your students.
    Give feedback frequently, even if only very brief.

Although Lauren’s experience is primarily from higher education (post-18), this advice is also useful for K-12 educators.

What about digital equity and inclusion?

All our seminars include an opportunity to break out into small discussion groups, followed by an opportunity to ask questions of the speaker. We had an animated follow-up discussion with Lauren, with many questions focused on issues of representation and inclusion. Some questions related to the digital divide and how we could support learners who didn’t have access to the technology they need. There were also questions from breakout groups about the participation of groups that are typically under-represented in computing education in online learning experiences, and accessibility for those with special educational needs and disabilities (SEND). While there is more work needed in this area, there’s also no one-size-fits-all approach to working with students with special needs, whether that’s due to SEND or to material resources (e.g. access to technology). What works for one student based on their needs might be entirely ineffective for others. Overall, the group concluded that there was a need for much more research in these areas, particularly at K-12 level.

Much anxiety has been expressed in the media, and more formally through bodies such as the World Economic Forum and UNESCO, about the potential long-lasting educational impact of the current period of school closures on disadvantaged students and communities. Research into the most inclusive way of supporting students through remote teaching will help here, as will the efforts of governments, charities, and philanthropists to provide access to technology to learners in need.

At the Raspberry Pi Foundation, we offer lots of free resources for students, educators, and parents to help them engage with computing education during the current school closures and beyond.

How should the education community move forward?

Lauren’s seminar made it clear to me that she was able to draw on decades of research studies into online and hybrid learning, and that we should take lessons from these before jumping to conclusions about the future. In both higher education (tertiary, university) and K-12 (primary, secondary) education contexts, we do not yet know the educational impact of the teaching experiments we have found ourselves engaging in at short notice. As Charles Hodges and colleagues wrote recently in Educause, what we are currently engaging in can only really be described as emergency remote teaching, which stands in stark contrast to planned online learning that is designed much more carefully with pedagogy, assessment, and equity in mind. We should ensure we learn lessons from the online learning research community rather than making it up as we go along.

Today many writers are reflecting on the educational climate we find ourselves in and on how it will impact educational policy and decision-making in the future. For example, an article from the Brookings Institution suggests that the experiences of home teaching and learning that we’ve had in the last couple of months may lead to both an increased use of online tools at home, an increase in home schooling, and a move towards competency-based learning. An article by Jo Johnson (President’s Professorial Fellow at King’s College London) on the impact of the pandemic on higher education, suggests that traditional universities will suffer financially due to a loss of income from international students less likely to travel to universities in the UK, USA, and Australia, but that the crisis will accelerate take-up of online, distance-learning, and blended courses for far-sighted and well-organised institutions that are ready to embrace this opportunity, in sum broadening participation and reducing elitism. We all need to be ready and open to the ways in which online and hybrid learning may change the academic world as we know it.

Next up in our seminar series

If you missed this seminar, you can find Lauren’s presentation slides and a recording of her talk on our seminars page.

Next Tuesday, 19 May at 17:00–18:00 BST, we will welcome Juan David Rodríguez from the Instituto Nacional de Tecnologías Educativas y de Formación del Profesorado (INTEF) in Spain. His seminar talk will be about learning AI at school, and about a new tool called LearningML. To join the seminar, simply sign up with your name and email address and we’ll email the link and instructions. If you attended Lauren’s seminar, the link remains the same.

The post Making the best of it: online learning and remote teaching appeared first on Raspberry Pi.

Noticia Original

Fix slow Nintendo Switch play with your Raspberry Pi

Is your Nintendo Switch behaving more like a Nintendon’t due to poor connectivity? Well, TopSpec (hosted Chris Barlas) has shared a brilliant Raspberry Pi-powered hack on YouTube to help you fix that.

 

Here’s the problem…

When you play Switch online, the servers are peer-to-peer. The Switches decide which Switch’s internet connection is more stable, and that player becomes the host.

However, some users have found that poor internet performance causes game play to lag. Why? It’s to do with the way data is shared between the Switches, as ‘packets’.

 

What are packets?

Think of it like this: 200 postcards will fit through your letterbox a few at a time, but one big file wrapped as a parcel won’t. Even though it’s only one, it’s too big to fit. So instead, you could receive all the postcards through the letterbox and stitch them together once they’ve been delivered.

Similarly, a packet is a small unit of data sent over a network, and packets are reassembled into a whole file, or some other chunk of related data, by the computer that receives them.

Problems arise if any of the packets containing your Switch game’s data go missing, or arrive late. This will cause the game to pause.

Fix Nintendo Switch Online Lag with a Raspberry Pi! (Ethernet Bridge)

Want to increase the slow internet speed of your Nintendo Switch? Having lag in games like Smash, Mario Maker, and more? Well, we decided to try out a really…

Chris explains that games like Call of Duty have code built in to mitigate the problems around this, but that it seems to be missing from a lot of Switch titles.

 

How can Raspberry Pi help?

The advantage of using Raspberry Pi is that it can handle wireless networking more reliably than Nintendo Switch on its own. Bring the two devices together using a LAN adapter, and you’ve got a perfect pairing. Chris reports speeds up to three times faster using this hack.

A Nintendo Switch > LAN adaptor > Raspberry Pi

He ran a download speed test using a Nintendo Switch by itself, and then using a Nintendo Switch with a LAN adapter plugged into a Raspberry Pi. He found the Switch connected to the Raspberry Pi was quicker than the Switch on its own.

At 02mins 50secs of Chris’ video, he walks through the steps you’ll need to take to get similar results.

We’ve handily linked to some of the things Chris mentions here:

 

 

To test his creation, Chris ran a speed test downloading a 10GB game, Pokémon Shield, using three different connection solutions. The Raspberry Pi hack came out “way ahead” of the wireless connection relying on the Switch alone. Of course, plugging your Switch directly into your internet router would get the fastest results of all, but routers have a habit of being miles away from where you want to sit and play.

Have a look at TopSpec on YouTube for more great videos.

The post Fix slow Nintendo Switch play with your Raspberry Pi appeared first on Raspberry Pi.

Noticia Original

Go back in time with a Raspberry Pi-powered radio

Take a musical trip down memory lane all the way back to the 1920s.

Sick of listening to the same dozen albums on repeat, or feeling stifled by the funnel of near-identical YouTube playlist rabbit holes? If you’re looking to broaden your musical horizons and combine that quest with a vintage-themed Raspberry Pi–powered project, here’s a great idea…

Alex created a ‘Radio Time Machine’ that covers 10 decades of music, from the 1920s up to the 2020s. Each decade has its own Spotify playlist, with hundreds of songs from that decade played randomly. This project with the look of a vintage radio offers a great, immersive learning experience and should throw up tonnes of musical talent you’ve never heard of.

In the comments section of their reddit post, Alex explained that replacing the screen of the vintage shell they housed the tech in was the hardest part of the build. On the screen, each decade is represented with a unique icon, from a gramophone, through to a cassette tape and the cloud. Here’s a closer look at it:

Now let’s take a look at the hardware and software it took to pull the whole project together…

Hardware:

  • Vintage Bluetooth radio (Alex found this affordable one on Amazon)
  • Raspberry Pi 4
  • Arduino Nano
  • 2 RGB LEDs for the dial
  • 1 button (on the back) to power on/off (long press) or play the next track (short press)

The Raspberry Pi 4 audio output is connected to the auxiliary input on the radio (3.5mm jack).

Software:

    • Mopidy library (Spotify)
    • Custom NodeJS app with JohnnyFive library to read the button and potentiometer values, trigger the LEDs via the Arduino, and load the relevant playlists with Mopidy

Take a look at the video on reddit to hear the Radio Time Machine in action. The added detail of the white noise that sounds as the dial is turned to switch between decades is especially cool.

How do you find ten decades of music?

Alex even went to the trouble of sharing each decade’s playlist in the comments of their original reddit post.

Here you go:

1920s
1930s
1940s
1950s
1960s
1970s
1980s
1990s
2000s
2010s

Comment below to tell us which decade sounds the coolest to you. We’re nineties kids ourselves!

The post Go back in time with a Raspberry Pi-powered radio appeared first on Raspberry Pi.

Noticia Original

Retro Nixie tube lights get smart

Nixie tubes: these electronic devices, which can display numerals or other information using glow discharge, made their first appearance in 1955, and they remain popular today because of their cool, vintage aesthetic. Though lots of companies manufactured these items back in the day, the name ‘Nixie’ is said to derive from a Burroughs corporation’s device named NIX I, an abbreviation of ‘Numeric Indicator eXperimental No. 1’.

We liked this recent project shared on reddit, where user farrp2011 used Raspberry Pi  to make his Nixie tube display smart enough to tell the time.

A still from Farrp2011’s video shows he’s linked the bulb displays up to tell the time

Farrp2011’s set-up comprises six Nixie tubes controlled by Raspberry Pi 3, along with eight SN74HC shift registers to turn the 60 transistors on and off that ground the pin for the digits to be displayed on the Nixie tubes. Sounds complicated? Well, that’s why farrp2011 is our favourite kind of DIY builder — they’ve put all the code for the project on GitHub.

Tales of financial woe from users trying to source their own Nixie tubes litter the comments section on the reddit post, but farrp2011 says they were able to purchase the ones used in this project for about about $15 each on eBay. Here’s a closer look at the bulbs, courtesy of a previous post by farrp2011 sharing an earlier stage of project…

Farrp2011 got started with one, then two Nixie bulbs before building up to six for the final project

Digging through the comments, we learned that for the video, farrp2011 turned their house lights off to give the Nixie tubes a stronger glow. So the tubes are not as bright in real life as they appear. We also found out that the drop resistor is 22k, with 170V as the supply. Another comments section nugget we liked was the name of the voltage booster boards used for each bulb: “Pile o’Poo“.

Upcoming improvements farrp201 has planned include displaying the date, temperature, and Bitcoin exchange rate, but more suggestions are welcome. They’re also going to add some more capacitors to help with a noise problem and remove the need for the tubes to be turned off before changing the display.

And for extra nerd-points, we found this mesmerising video from Dalibor Farný showing the process of making Nixie tubes:

The post Retro Nixie tube lights get smart appeared first on Raspberry Pi.

Noticia Original

Code Robotron: 2084’s twin-stick action | Wireframe #38

News flash! Before we get into our Robotron: 2084 code, we have some important news to share about Wireframe: as of issue 39, the magazine will be going monthly.

The new 116-page issue will be packed with more in-depth features, more previews and reviews, and more of the guides to game development that make the magazine what it is. The change means we’ll be able to bring you new subscription offers, and generally make the magazine more sustainable in a challenging global climate.

As for existing subscribers, we’ll be emailing you all to let you know how your subscription is changing, and we’ll have some special free issues on offer as a thank you for your support.

The first monthly issue will be out on 4 June, and subsequent editions will be published on the first Thursday of every month after that. You’ll be able to order a copy online, or you’ll find it in selected supermarkets and newsagents if you’re out shopping for essentials.

We now return you to our usual programming…

Move in one direction and fire in another with this Python and Pygame re-creation of an arcade classic. Raspberry Pi’s own Mac Bowley has the code.

Robotron: 2084 is often listed on ‘best game of all time’ lists, and has been remade and re-released for numerous systems over the years.

Robotron: 2084

Released back in 1982, Robotron: 2084 popularised the concept of the twin-stick shooter. It gave players two joysticks which allowed them to move in one direction while also shooting at enemies in another. Here, I’ll show you how to recreate those controls using Python and Pygame. We don’t have access to any sticks, only a keyboard, so we’ll be using the arrow keys for movement and WASD to control the direction of fire.

The movement controls use a global variable, a few if statements, and two built-in Pygame functions: on_key_down and on_key_up. The on_key_down function is called when a key on the keyboard is pressed, so when the player presses the right arrow key, for example, I set the x direction of the player to be a positive 1. Instead of setting the movement to 1, instead, I’ll add 1 to the direction. The on_key_down function is called when a button’s released. A key being released means the player doesn’t want to travel in that direction anymore and so we should do the opposite of what we did earlier – we take away the 1 or -1 we applied in the on_key_up function.

We repeat this process for each arrow key. Moving the player in the update() function is the last part of my movement; I apply a move speed and then use a playArea rect to clamp the player’s position.

The arena background and tank sprites were created in Piskel. Separate sprites for the tank allow the turret to rotate separately from the tracks.

Turn and fire

Now for the aiming and rotating. When my player aims, I want them to set the direction the bullets will fire, which functions like the movement. The difference this time is that when a player hits an aiming key, I set the direction directly rather than adjusting the values. If my player aims up, and then releases that key, the shooting will stop. Our next challenge is changing this direction into a rotation for the turret.

Actors in Pygame can be rotated in degrees, so I have to find a way of turning a pair of x and y directions into a rotation. To do this, I use the math module’s atan2 function to find the arc tangent of two points. The function returns a result in radians, so it needs to be converted. (You’ll also notice I had to adjust mine by 90 degrees. If you want to avoid having to do this, create a sprite that faces right by default.)

To fire bullets, I’m using a flag called ‘shooting’ which, when set to True, causes my turret to turn and fire. My bullets are dictionaries; I could have used a class, but the only thing I need to keep track of is an actor and the bullet’s direction.

Here’s Mac’s code snippet, which creates a simple twin-stick shooting mechanic in Python. To get it working on your system, you’ll need to install Pygame Zero. And to download the full code and assets, go here.

You can look at the update function and see how I’ve implemented a fire rate for the turret as well. You can edit the update function to take a single parameter, dt, which stores the time since the last frame. By adding these up, you can trigger a bullet at precise intervals and then reset the timer.

This code is just a start – you could add enemies and maybe other player weapons to make a complete shooting experience.

Get your copy of Wireframe issue 38

You can read more features like this one in Wireframe issue 38, available directly from Raspberry Pi Press — we deliver worldwide.

And if you’d like a handy digital version of the magazine, you can also download issue 38 for free in PDF format.

Make sure to follow Wireframe on Twitter and Facebook for updates and exclusive offers and giveaways. Subscribe on the Wireframe website to save up to 49% compared to newsstand pricing!

The post Code Robotron: 2084’s twin-stick action | Wireframe #38 appeared first on Raspberry Pi.

Noticia Original