H4J6O

            Alien technologies: Arpanet & Unix.
            Independence Day III (20xx).

Arduino to AVR
--------------

  +---------+-----+---------+
  | Arduino | AVR | Role    |
  +---------+-----+---------+
  | D13.....|.PB5.|.SCK     |
  | D12.....|.PB4.|.MISO    |
  | D11.....|.PB3.|.MOSI    |
  | D10.....|.PB2.|.SS      |
  | D9......|.PB1.|.IO9     |
  | D8......|.PB0.|.IO8     |
  |         |     |         |
  | D7......|.PD7.|.IO7     |
  | D6......|.PD6.|.IO6     |
  | D5......|.PD5.|.IO5     |
  | D4......|.PD4.|.IO4     |
  | D3......|.PD3.|.IO3     |
  | D2......|.PD2.|.IO2     |
  | D1......|.PD1.|.IO1     |
  | D0......|.PD0.|.IO0     |
  |         |     |         |
  | A5......|.PC5.|.AD5/SCI |
  | A4......|.PC4.|.AD4/SDA |
  | A3......|.PC3.|.AD3     |
  | A2......|.PC2.|.AD2     |
  | A1......|.PC1.|.AD1     |
  | A0......|.PC0.|.AD0     |
  +---------+-----+---------+

Building Voltmeter with Simultron
---------------------------------

Begin
   1. SimulIDE probe have voltmeter built-in.
   2. Simultron have digital components only
Commit:)

Visual Python and Windows
-------------------------

Install Python 2.7.13 64Bit

  http://python.org/ftp/python/2.7.9/python-2.7.9.amd64.msi

Install VPython-Win-64-Py2.7-6.11 from

  http://vpython.org/contents/download_windows.html

Run python from command prompt.

  >>> import pip
  >>> pip.main(['install','pyserial'])

Arduino and Windows
-------------------

Install com0com with errors. Select [OK] or [Continue] on each error. Install N8VBvCOMSetup-226a.exe now. Check for available ports with SimulIDE:

  + Place Arduino Uno.
  + RClick on Arduino board.
  + Check what ports are available, what ports are newly added.
  + Check the connection with two PuTTYes on new ports.
    For example, COM4,9600 -- COM5,9600

Serial communication (SimulIDE,
VisualPython, on host -- no VirtualBox)
---------------------------------------

Or.. just set CPU cores: 4 in virtual box manager.

Phase 0: Segments

  void setup() {
    DDRD = DDRD&0x01|0xfe;
  }

  int x = 1;

  void loop() {
    digitalWrite( x, HIGH);
    delay( 500);
    x = x > 7 ? 1 : x + 1;
  }

Phase 1: Font ()

/*
                                              ---------
  7SEG-a  PD1  R 200            a ---/\/\/---|  aaaaa  |
  7SEG-b  PD2  R 200            b ---/\/\/---| f     b |
  7SEG-c  PD3  R 200            c ---/\/\/---| f     b |
  7SEG-d  PD4  R 200            d ---/\/\/---|  ggggg  |
  7SEG-e  PD5  R 200            e ---/\/\/---| e     c |
  7SEG-f  PD6  R 200            f ---/\/\/---| e     c |
  7SEG-g  PD7  R 200            g ---/\/\/---|  ddddd  |
                                              ---------
  [0123456789AbcdEFGhijKLMnoPqrStuWxYZ _-=]    |     |
                                              dot   GND */
  int x = 0;

  int i2c[] = { 0x7e, 0x0c, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0x0e,
                0xfe, 0xde, 0xee, 0xf8, 0x72, 0xbc, 0xf2, 0xe2,
                0x7a, 0xe8, 0x32, 0x1a, 0xec, 0x70, 0x6c, 0xa8,
                0xb8, 0xe6, 0xce, 0xa0, 0xd8, 0xf0, 0x7c, 0x38,
                0xfc, 0x28, 0xdc, 0x92, 0x00, 0x10, 0x80, 0x90 };

  void setup() {
    Serial.begin(9600);
    DDRD = DDRD&0x01|0xfe;
  }

  void loop() {
    PORTD = i2c[x];
    delay( 1000);
    x = x >= 39 ? 0 : x + 1;
  }

Phase 2. Arduino talks (via serial)

/*
                                              ---------
  7SEG-a  PD1  R 200            a ---/\/\/---|  aaaaa  |
  7SEG-b  PD2  R 200            b ---/\/\/---| f     b |
  7SEG-c  PD3  R 200            c ---/\/\/---| f     b |
  7SEG-d  PD4  R 200            d ---/\/\/---|  ggggg  |
  7SEG-e  PD5  R 200            e ---/\/\/---| e     c |
  7SEG-f  PD6  R 200            f ---/\/\/---| e     c |
  7SEG-g  PD7  R 200            g ---/\/\/---|  ddddd  |
                                              ---------
  [0123456789AbcdEFGhijKLMnoPqrStuWxYZ _-=]    |     |
                                              dot   GND */
  int x = 0;
  char s[] = "    ";
  int i2c[] = { 0x7e, 0x0c, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0x0e,
                0xfe, 0xde, 0xee, 0xf8, 0x72, 0xbc, 0xf2, 0xe2,
                0x7a, 0xe8, 0x32, 0x1a, 0xec, 0x70, 0x6c, 0xa8,
                0xb8, 0xe6, 0xce, 0xa0, 0xd8, 0xf0, 0x7c, 0x38,
                0xfc, 0x28, 0xdc, 0x92, 0x00, 0x10, 0x80, 0x90 };

  void setup() {
    Serial.begin(9600);
    DDRD = DDRD&0x01|0xfe;
          while ( !Serial);
  }

  unsigned char c=0;

  void loop() {
      sprintf(s, "%c", c>9?c+0x37:c+0x30);
      Serial.write( s);
      PORTD=PORTD&0x01|i2c[c]&0xfe;
      c=c<39?c+1:0;
      delay( 500);
  }

Phase 3. Arduino listens (Pendulum)

Pendulum is talking:

  # Swing -- a seat suspended by ropes or chains, on which
  #          someone may sit and swing back and forth.
  # Works with simutron 1.01 (tronSerialEcho.simu)
  # Simutron significantly slows down our Virtual machine,
  # So next time we are switching to real Arduinos.

  import serial
  from visual import *
  from math import *

  SCREEN = 800;
  PENLEN = 10;  # pendulum length
  BALLRA = 1.5  # ball radius
  PERSPE = PENLEN / 3
  INITDA = .013
  scene.width  = SCREEN;
  scene.height = SCREEN;

  G      = 9.81

  w = box( color=(.2,.2,.2), pos=(0,0,-2),  \
           size=( 2*PENLEN+2*BALLRA+PERSPE, \
                  2*PENLEN+2*BALLRA+PERSPE, \
                  .1                        \
           )                                \
      )
  c = cylinder( pos=(0,0,-2), axis=(0,0,1), \
                length = 4, color=color.red \
      )
  b = box( color=color.blue, size=(1,PENLEN,1))
  s = sphere( color=color.green, radius=BALLRA)

  da = INITDA # initial speed
  a = da
  dam = 1
  h = PENLEN
  c = 0
  cold = 0
  t = 0

  tlist = ['0','1','2','3','4','5','6','7','8','9', \
           'A','B','C','D','E','F','G','H','I','J', \
           'K','L','M','N','O','P','Q','R','S','T', \
           'U','V','W','X','Y','Z','[','\\',']','^' ]

  ser = serial.Serial('COM4',9600)

  while True:
      c += 1
      rate(200)
      b.axis=( cos(a), sin(a), 0)
      b.pos=( PENLEN/2 * sin(a),-PENLEN/2 * cos(a), 0)
      s.pos=( PENLEN * sin(a), -PENLEN * cos(a), 0)

      h = PENLEN * (1 - cos(a))

      tmp = INITDA*INITDA - 0.000001*G*h
      if tmp > 0:
          da = sqrt( tmp)
      else:
          dam = sign( a)

      if h < 0.001:
          if (c - cold) != 1 and c > 3:
              t = 0 if t > 38 else t + 1
              # print(t)
              INITDA = 0.5 * INITDA
              if da < 0.0001:
                  INITDA = 0.014
              ser.write(tlist[t])
          cold = c

      a = a - da * dam

Arduino is listening:

/*
                                              ---------
  7SEG-a  PD1  R 200            a ---/\/\/---|  aaaaa  |
  7SEG-b  PD2  R 200            b ---/\/\/---| f     b |
  7SEG-c  PD3  R 200            c ---/\/\/---| f     b |
  7SEG-d  PD4  R 200            d ---/\/\/---|  ggggg  |
  7SEG-e  PD5  R 200            e ---/\/\/---| e     c |
  7SEG-f  PD6  R 200            f ---/\/\/---| e     c |
  7SEG-g  PD7  R 200            g ---/\/\/---|  ddddd  |
                                              ---------
  [0123456789AbcdEFGhijKLMnoPqrStuWxYZ _-=]    |     |
                                              dot   GND */
  int x = 0;
  char s[] = "    ";
  int i2c[] = { 0x7e, 0x0c, 0xb6, 0x9e, 0xcc, 0xda, 0xfa, 0x0e,
                0xfe, 0xde, 0xee, 0xf8, 0x72, 0xbc, 0xf2, 0xe2,
                0x7a, 0xe8, 0x32, 0x1a, 0xec, 0x70, 0x6c, 0xa8,
                0xb8, 0xe6, 0xce, 0xa0, 0xd8, 0xf0, 0x7c, 0x38,
                0xfc, 0x28, 0xdc, 0x92, 0x00, 0x10, 0x80, 0x90 };

  void setup() {
      Serial.begin(9600);
      DDRD = DDRD&0x01|0xfe;
      while ( !Serial);
  }

  void loop() {
      if ( Serial.available() > 0) {
        int inByte = Serial.read();
        inByte=inByte<0x3A?inByte-0x30:inByte-0x37;
        PORTD=PORTD&0x01|i2c[inByte]&0xfe;
      }
  }

Annex A. Build with ino
-----------------------

  virtu@UBox:~/ino/beep$ tree
  .
  ├── lib
  └── src
      └── sketch.ino

  2 directories, 1 file
  virtu@UBox:~/ino/beep$ cat src/sketch.ino

  #define LED_PIN 13

  void setup()
  {
      pinMode(LED_PIN, OUTPUT);
  }

  void loop()
  {
      digitalWrite(LED_PIN, HIGH);
      delay(100);
      digitalWrite(LED_PIN, LOW);
      delay(900);
  }

Links
-----

[1]. Null Modem Emulator (com0com)
     http://www.magsys.co.uk/comcap/onlinehelp
     /null_modem_emulator_com0com.htm

[2]. http://radiokot.ru/forum/viewtopic.php?f=24&t=71757
     Вот эта вроде фриварня:
       http://www.ritm.ru/documentation/program/N8VBvCOMSetup-226a.exe

