locked
Tinkering Arduino and Small Basic RRS feed

All replies

  • this is only an aproximation and simplified scheme of course

    • scheme is missing a gnd(ground) link wire with every led
    • wiring is shown only for first led (idem wiring for other leds)
    • leds are missing an 100 ohm resistor each on gnd wire
    • in order to select leds power levels u must connect them only to pwm marked pins

    c part example for one led:

    #define ledPin 9
    #define ledPin2 10
    #define ledPin3 11
    void setup()
    {
    
      pinMode(9, OUTPUT);
      pinMode(10, OUTPUT);
      pinMode(11, OUTPUT);
    
    }
    
    void loop(){
    
    for (int i=0; i<=255; i=i+5) // ascending value for i
    {
    analogWrite(ledPin3, i*0.1); // sets brightess level to i
    analogWrite(ledPin2, i*0.1);
    analogWrite(ledPin, i);
    delay(18); // pauses for 18ms
    }
    for (int i=255; i>=0; i=i-5) // descending value for i
    {
    analogWrite(ledPin3, i*0.1);
    analogWrite(ledPin2, i*0.1);
    analogWrite(ledPin, i);
    
    delay(18);
    }  
    
    }



    • Edited by Tryhest Friday, October 21, 2016 5:31 AM
    Friday, October 21, 2016 5:27 AM
  • This is my LED signal circuit. (GZN399-2)

    Screen shot of a program OSOYOO UNO R3 - LED Signal 0.41

    Arduino sketch is:

    // LED signal
    
    const int PIN_GREEN = 3;
    const int PIN_YELLOW = 5;
    const int PIN_RED = 9;
    
    void led(int pin) {
      for (int i = 0; i <= 255; i++)  // ascending value for i
      {
        analogWrite(pin, i);          // sets brightess level to i
        delay(5);                     // pauses for 5ms
      }
      for (int i = 255; i >= 0; i--)  // descending value for i
      {
        analogWrite(pin, i);
        delay(5);
      }  
    }
    
    void setup()
    {
      pinMode(PIN_GREEN, OUTPUT);
      pinMode(PIN_YELLOW, OUTPUT);
      pinMode(PIN_RED, OUTPUT);
    }
    
    void loop()
    {
      led(PIN_GREEN);
      led(PIN_YELLOW);
      led(PIN_RED);
    }


    Nonki Takahashi


    • Edited by Nonki Takahashi Friday, March 3, 2017 1:15 PM updated a link and an image
    Saturday, October 22, 2016 5:14 AM
  • Fantastic circuit, wow !!!

    this is my retouched version with real LED. :     NCH457-0

         



    • Edited by YLedEditor Saturday, October 22, 2016 3:25 PM
    Saturday, October 22, 2016 2:31 PM
    Answerer
  • code for traffic lights simulation

    sequence: red / red-yel / green / 3x flash green / yellow

    'red
    out 10 0
    out 11 0
    out 12 255
    out 1 199
    out 2 199
    out 3 199
    out 5 199
    out 6 199
    out 7 199
    delay 3500

    'red-yel
    out 10 0
    out 11 0
    out 12 255
    out 5 0
    out 6 255
    out 7 255
    delay 1000

    'green
    out 10 199
    out 11 199
    out 12 199
    out 5 199
    out 6 199
    out 7 199
    out 1 0
    out 2 255
    out 3 0
    delay 3500

    out 10 199
    out 11 199
    out 12 199
    out 5 199
    out 6 199
    out 7 199
    out 1 199
    out 2 199
    out 3 199
    delay 500

    out 10 199
    out 11 199
    out 12 199
    out 5 199
    out 6 199
    out 7 199
    out 1 0
    out 2 255
    out 3 0
    delay 500

    out 10 199
    out 11 199
    out 12 199
    out 5 199
    out 6 199
    out 7 199
    out 1 199
    out 2 199
    out 3 199
    delay 500

    out 10 199
    out 11 199
    out 12 199
    out 5 199
    out 6 199
    out 7 199
    out 1 0
    out 2 255
    out 3 0
    delay 500

    out 10 199
    out 11 199
    out 12 199
    out 5 199
    out 6 199
    out 7 199
    out 1 199
    out 2 199
    out 3 199
    delay 500

    out 10 199
    out 11 199
    out 12 199
    out 5 199
    out 6 199
    out 7 199
    out 1 0
    out 2 255
    out 3 0
    delay 500

    'yell
    out 1 199
    out 2 199
    out 3 199
    out 5 0
    out 6 255
    out 7 255
    delay 2000

    Saturday, October 22, 2016 5:41 PM
  • I wrote a blog about LCD control.

    Happy Birthday Small Basic - The 8th Anniversery


    Nonki Takahashi

    Sunday, October 23, 2016 10:03 AM
  • nice arduino and rasp.pi examples and tutorials: http://randomnerdtutorials.com/
    Wednesday, November 9, 2016 2:59 AM
  • connecting arduino to vga monitor: LBQ108

    fonts:

    libs on: https://github.com/smaffer/vgax





    • Edited by Tryhest Wednesday, December 14, 2016 2:34 PM
    Tuesday, December 13, 2016 8:00 AM
  • display some random numbers on ada neopixel arduino led board: LGQ874

    code to put on arduino uno:

    #include <Adafruit_NeoPixel.h>
    #ifdef __AVR__
    #include <avr/power.h>
    #endif
    #define PIN 6
    byte numpixels = 40;
    float pi = 3.1415 / 180;
    Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numpixels, PIN, NEO_BRG + NEO_KHZ800);
    
    void setup() {
      Serial.begin(115200);
      pixels.begin();
    
    }
    int pp = -1, red, green, blue;
    void loop() {
    
      byte sw = 0;
      while (Serial.available() > 0) {
        pp = Serial.parseInt();
        red = Serial.parseInt();
        // do it again:
        blue = Serial.parseInt();
        green = Serial.parseInt();
        if (Serial.read() == '\n') {
    
          for (byte pix = 0; pix < 40; pix ++)
          {
    
    
            long cc = pixels.Color(red, green, blue);
    
            if (pp == pix) pixels.setPixelColor(pix, cc);
          }
          pixels.show();
          Serial.println("ok");
        }
      }
    }

    results:



    steps:

    • note the speed 115200 and Newline termination
    • after that works ok, load sb app, adjust com port, run it and enjoy
    • if u want to increase brighness of leds, just increase ff on line 46 ( not over 15!)






    • Edited by Tryhest Tuesday, January 31, 2017 7:30 AM
    Tuesday, January 31, 2017 6:39 AM
  • scroller 4 neopixel: QLF691

    Thursday, February 2, 2017 7:55 AM
  • arduino joystick: QHM145

    steps:

    code for arduino:

    void setup() {
      Serial.begin(115200);
    }
    
    void loop() {
      Serial.print("X ");
      Serial.println(analogRead(0));
      Serial.print("\r");
      Serial.print("Y ");
      Serial.println(analogRead(2));
      Serial.print("\r\r");
      delay(30); //adjust delay here
    }

    • Edited by Tryhest Thursday, February 2, 2017 11:49 AM
    Thursday, February 2, 2017 11:46 AM
  • GRBL sender: QMG224

    sends HPGL file to grbl arduino plotter/3d printer

      requires:

      • arduino uno
      • arduino cnc shield
      • grbl downloader: Xloader
      • grbl v1.1 for arduino
      • plotter/3d printer




    • Edited by Tryhest Monday, March 6, 2017 5:06 AM
    Monday, March 6, 2017 4:59 AM
  • arduino oled display: XQN665

    gets a definition from dictionary and sends it to arduino oled display

    code for arduino:

    //wemos D1 pinout
    #define sclk D5
    #define mosi D7
    #define cs   D8
    #define rst  D2
    #define dc   D1
    
    long BLACK       =    0x0000;
    long BLUE        =    0x001F;
    long RED         =    0xF800;
    long GREEN       =    0x07E0;
    long CYAN        =    0x07FF;
    long MAGENTA     =    0xF81F;
    long YELLOW      =    0xFFE0;
    long WHITE       =    0xFFFF;
    
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1331.h>
    #include <SPI.h>
    
    Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, rst);
    
    void setup(void) {
      Serial.begin(115200);
      display.begin();
      display.setTextSize(1);
    }
    
    int p1 = 0;
    String ttw = ">>";
    
    void loop() {
      if (p1 == 0) {
        int bb = random(20) * 12;
        for (int16_t x = 0; x < 64; x ++)
          display.drawFastHLine(0, x, 96 , display.Color565(x * 2, 0, bb));
        display.setTextColor(WHITE);
        display.setCursor(1, 1);
        display.print( ttw);
        p1 = 1;
      }
      if (Serial.available() > 0) { // read the incoming char:
        char ch = Serial.read();
    
        if (ch == '$') {//cls cmd
          cls();
          ttw = ""; }
        //font size cmds:
        else if (ch == '#')display.setTextSize(3);
        else if (ch == '!')display.setTextSize(1);
        else if (ch == '@')display.setTextSize(2);
        else ttw += ch;
        display.setCursor(1, 1);
        display.print( ttw);
      }
    }
    
    void cls() {int bb = random(20) * 12;
      for (int16_t x = 0; x < 64; x ++)     display.drawFastHLine(0, x, 96 , display.Color565(x * 2, 0, bb));
    }



    • Edited by Tryhest Friday, May 19, 2017 11:36 AM
    Friday, May 19, 2017 11:23 AM
  • one digit led 8-seg hexaclock: NVD845

    requirements:

    • arduino uno or similar
    • 8-seg led module
    • 8 resistors 220 ohm
    • testboard and wires

    displays clock in following mode:

    hour is displayed in hexa mode, by 3 flashing:

    • midnight= 0
    • 1-9 am digits
    • 10 am/pm =A
    • 11 am/pm= B
    • noon = C

    minutes are displayed by sequencing 2 digits

    display remains the last minute number

    refresh is every 5 secs

    arduino code:

    void setup() {
      Serial.begin(115200);
      while (!Serial);
    
      for (int x = 2; x < 12; x++) {
        pinMode(x, OUTPUT);
        digitalWrite(x, HIGH);
      }
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      for (int x = 4; x < 12; x++) digitalWrite(x, HIGH);
    }
    int aa[] = {18, 126, 49, 52, 92, 30, 16, 20};
    
    void loop() {
    
      if (Serial.available() > 0) {
        // read the incoming byte:
        char nn = ' ';
        String ss = "";
        while (nn != 13) {
          nn = Serial.read();
          ss += nn;}
          
        Serial.println(ss);
        for (int x = 4; x < 12; x++) digitalWrite(x, bitRead(ss.toInt(), x - 4 )); //aa[nn%3]
        delay(150);}
    }

    wiring:

    • used arduino pins 3-10
    • pin 3 is used for display selection and is always on
    • in this code pin 16(bin) is connected to dot segment and can be ommited

    result:


    notes for image:

    - covered part are not used for this project

    - used arduino leonardo board with nice old pentium II cover

    • Edited by Tryhest Saturday, May 27, 2017 7:24 AM
    Saturday, May 27, 2017 7:15 AM
  • arduino radio tunner: DFQ043

    requirements:

    edit sb program for radio channels/station names

    arduino code:

    // TEA5767 Example
    
    #include <Wire.h>
    #include <TEA5767Radio.h>
    
    TEA5767Radio radio = TEA5767Radio();
    
    void setup()
    { 
      Wire.begin();
      radio.setFrequency(97.3); // pick your own frequency
    }
    
    void loop()
    {
       if (Serial.available() > 0) {
        // read the incoming byte:
        char nn = ' ';
        String ss = "";
        while (nn != 13) {
           nn = Serial.read();
          ss += nn;
        }
         radio.setFrequency(ss.toFloat());
       } 
    }

    Wednesday, June 14, 2017 10:42 AM
  • utility for drawing el. circuits v0.1: KCC353

    • shortloop test incl.
    • just led draw (for now)
    • more to come soon

    Sunday, June 18, 2017 11:48 AM
  • electronic board draw utility: TWP322

    • to move resistance use mswheel for vertical ands leftmsbutton+wheel to adjust horizontaly position
    • only draw functons, no test or emulation
    • use undo to remove last added object

    Monday, June 19, 2017 8:40 PM
  • small update: ZZD851

    • added labels

    Tuesday, June 20, 2017 3:21 AM
  • now added 3d preview of resistors (only), on board: DHP928

    Wednesday, June 21, 2017 5:56 AM
  • update: xtb326-0

    • added wires and pins

    Wednesday, June 21, 2017 6:47 PM
  • also added color rings: SZM470

    Wednesday, June 21, 2017 7:21 PM
  • resistor calc: QTK092

    Friday, June 23, 2017 4:09 AM
  • updated resistance coloring: SZM470-0

    • resistance can be defined as e.g. 2200 or 2.2k or 2k2
    • if ommited, 100 ohm default resistance displayed

     
    Saturday, June 24, 2017 6:19 AM
  • updateSZM470-2

    • added led coloring
    • added diodes in 3d view
    • corrected led pin length, and resistor size

    Saturday, June 24, 2017 4:50 PM
  • update: added diode polarity change  SZM470-3

                  -negative value reverses direction of diode



    • Edited by Tryhest Saturday, June 24, 2017 6:14 PM
    Saturday, June 24, 2017 6:07 PM
  • This is a program showing registers: BXZ994.

    Screen shot of a program Registers


    Nonki Takahashi

    Wednesday, August 30, 2017 9:20 AM
  • This program shows a circuit for tact switches: MXB654.

    Screen shot of a program Tact Switch


    Nonki Takahashi

    Wednesday, August 30, 2017 11:59 AM
  • u mean resistors?
    Thursday, August 31, 2017 6:03 PM
  • there's also a simpler version of keys connecting, if u use internal pull-up resistance

    Thursday, August 31, 2017 6:35 PM
  • it's also more convenient in case of more keys.

    just add pinMode(n ,INPUT_PULLUP); {n is input pin,2 in this example)

    Thursday, August 31, 2017 6:38 PM
  • another approach is to use analog inputs instead of digital ones. in that case every key has different resistor scaling up from 500 to 5k ohms. keep in mind that resistance changes with temperature change, so allow at least 50ohms of tolerance

    scheme of analog reading:

    5v------10k---------Resistor------GND
                             |
                         Analog

    also add to arduino code:  pinMode(An ,INPUT); |(n is analog port input 0-5)

    • Edited by Tryhest Thursday, August 31, 2017 7:07 PM
    Thursday, August 31, 2017 7:00 PM
  • u mean resistors?

    Yes!


    Nonki Takahashi

    Friday, September 1, 2017 7:10 AM
  • it's also more convenient in case of more keys.

    just add pinMode(n ,INPUT_PULLUP); {n is input pin,2 in this example)

    I found the details about your comment.  Thanks, Tryhest.

    Input Pullup Serial (ARDUINO > Examples > Digital)


    Nonki Takahashi

    Friday, September 1, 2017 9:57 AM
  • This is the circuit using pull-up: MXB654-1.

    Screen shot of a program Tact Switch with Pull-up


    Nonki Takahashi

    Friday, September 1, 2017 12:04 PM
  • And the code for Arduino is:

    /* Tact Switch with Pull-up
     * Copyright (c) 2017 Nonki Takahashi
     * The MIT License
     */
    
    int buttonA = 8;
    int buttonB = 9;
    int lastA = HIGH;
    int lastB = HIGH;
    int nowA = HIGH;
    int nowB = HIGH;
    
    void setup() {
      // put your setup code here, to run once:
      pinMode(buttonA, INPUT_PULLUP);
      pinMode(buttonB, INPUT_PULLUP);
      Serial.begin(9600);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      nowA = digitalRead(buttonA);
      nowB = digitalRead(buttonB);
      if (nowA == HIGH && lastA == LOW) {
        Serial.println("A");
      }
      if (nowB == HIGH && lastB == LOW) {
        Serial.println("B");
      }
      lastA = nowA;
      lastB = nowB;
      delay(200);
    }


    Nonki Takahashi

    Friday, September 1, 2017 12:07 PM
  • This is a game for the tact switches above: QZN342-6.

    Please modify following line for your setting.

    76.  status = LDCommPort.OpenPort("COM5", 9600)

    Screen shot of a program Turtle Dodger 0.7b


    Nonki Takahashi


    Friday, September 1, 2017 3:50 PM
  • simulates control boad of a printer/plotter: hhc193-1

    Saturday, December 30, 2017 6:31 PM
  • blue/white lcd board: HXM284

    Monday, January 1, 2018 7:45 PM