### Show setup info and objects with info
Source: https://lcgamboa.github.io/picsimlab_docs/stable/RemoteControlInterface.html
Shows the current board setup, processor, frequency, and all available objects with their values. The output ends with 'Ok'.
```text
info
Board: Arduino Uno
Processor: atmega328p
Frequency: 16000000 Hz
Use Spare: 1
board.out[00] LD_L= 254
part[00]: LEDs
part[00].out[08] LD_1= 254
part[00].out[09] LD_2= 30
part[00].out[10] LD_3= 254
part[00].out[11] LD_4= 254
part[00].out[12] LD_5 254
part[00].out[13] LD_6= 254
part[00].out[14] LD_7= 254
part[01]: Buzzer
part[01].out[02] LD_1= 140
part[02]: Push buttons
part[02].in[00] PB_1= 1
part[02].in[01] PB_2= 0
part[02].in[02] PB_3= 1
part[02].in[03] PB_4= 1
part[02].in[04] PB_5= 1
part[02].in[05] PB_6= 1
part[02].in[06] PB_7= 1
part[02].in[07] PB_8= 1
Ok
```
--------------------------------
### Get object values with get
Source: https://lcgamboa.github.io/picsimlab_docs/stable/RemoteControlInterface.html
Shows how to use the 'get' command to view input/output states of objects. The output is not shown here.
```text
get board.out[00]
get part[02].in[01]
```
--------------------------------
### info
Source: https://lcgamboa.github.io/picsimlab_docs/stable/RemoteControlInterface.html
The info command displays the current board setup and all available objects with their values.
```APIDOC
## info
### Description
Shows the actual setup information and all available objects with their values.
### Method
TCP command
### Endpoint
info
### Parameters
None
### Response
#### Success Response
- **Board** (string) - The board name.
- **Processor** (string) - The processor model.
- **Frequency** (string) - The clock frequency in Hz.
- **Use Spare** (integer) - Spare usage flag.
- **Objects** (object) - List of objects with their values.
#### Response Example
```
Board: Arduino Uno
Processor: atmega328p
Frequency: 16000000 Hz
Use Spare: 1
board.out[00] LD_L= 254
part[00]: LEDs
part[00].out[08] LD_1= 254
part[00].out[09] LD_2= 30
part[00].out[10] LD_3= 254
part[00].out[11] LD_4= 254
part[00].out[12] LD_5 254
part[00].out[13] LD_6= 254
part[00].out[14] LD_7= 254
part[01]: Buzzer
part[01].out[02] LD_1= 140
part[02]: Push buttons
part[02].in[00] PB_1= 1
part[02].in[01] PB_2= 0
part[02].in[02] PB_3= 1
part[02].in[03] PB_4= 1
part[02].in[04] PB_5= 1
part[02].in[05] PB_6= 1
part[02].in[06] PB_7= 1
part[02].in[07] PB_8= 1
Ok
```
```
--------------------------------
### Get individual pin states with get
Source: https://lcgamboa.github.io/picsimlab_docs/stable/RemoteControlInterface.html
Shows how to use the 'get' command to view individual pin states: digital, digital mean value, analog, and all info. The output includes the pin value and 'Ok'.
```text
#digital state
get pin[19]
pin[19]= 0
Ok
#digital mean value (0-200)
get pinm[19]
pin[18]= 100
Ok
#analog state
get apin[25]
apin[25]= 2.700
Ok
#all info
get pinl[13]
pin[13] D I 1 200 0.000 "PD7/7 "
Ok
```
--------------------------------
### Install tty0tty module with dkms-install.sh
Source: https://lcgamboa.github.io/picsimlab_docs/stable/tty0ttyInstallationandConfigurationLinux.html
Run these commands in the tty0tty/module/ folder to update the system, install build tools and kernel headers, then compile and load the tty0tty module.
```bash
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install gcc make linux-headers-`uname -r`
sudo ./dkms-install.sh
sudo modprobe tty0tty
```
--------------------------------
### Set pin value with set
Source: https://lcgamboa.github.io/picsimlab_docs/stable/RemoteControlInterface.html
Shows how to set the value of a pin using the 'set' command, with examples for digital and analog pins.
```text
#digital
set pin[10] 2
#analog
set apin[20] 2.345
```
--------------------------------
### Connect arm-none-eabi-gdb to PICSimLab
Source: https://lcgamboa.github.io/picsimlab_docs/stable/armgdbDebug.html
Start arm-none-eabi-gdb with the compiled .elf file, then connect to the simulator's GDB server on localhost port 1234 (the default port).
```bash
arm-none-eabi-gdb compiled_file.elf
```
```gdb
target extended-remote localhost:1234
```
--------------------------------
### Launch avr-gdb with compiled .elf file
Source: https://lcgamboa.github.io/picsimlab_docs/stable/avrgdbDebug.html
Run avr-gdb with the compiled .elf file as the parameter to start debugging in PicsimLab.
```bash
avr-gdb compiled_file.elf
```
--------------------------------
### cboard_x::Run_CPU - method start
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Boardcode.html
Starts the Run_CPU method of cboard_x. Declares local variables including an array alm of size 40. The code is incomplete as shown.
```cpp
void
cboard_x::Run_CPU(void)
{
int i;
int j;
unsigned char pi;
const picpin * pins;
unsigned int alm[40];
```
--------------------------------
### Launch xtensa-esp32-elf-gdb with the compiled ELF file
Source: https://lcgamboa.github.io/picsimlab_docs/stable/ESP32gdbDebug.html
Run the GDB debugger with the compiled .elf file as the argument to start debugging the code used in the simulator.
```bash
xtensa-esp32-elf-gdb compiled_file.elf
```
--------------------------------
### Board map file example (board.map)
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Picturemap.html
Example of a board.map file generated by Gimp image map editor. It defines clickable areas (rectangles and circles) with coordinates and href identifiers matching the board areas listed above. The file is saved as 'share/boards/X/board.map'.
```html
```
--------------------------------
### Set object input value with set
Source: https://lcgamboa.github.io/picsimlab_docs/stable/RemoteControlInterface.html
Shows how to set the value of an input object using the 'set' command. The example sets part[02].in[01] to 0 and then to 1.
```text
set part[02].in[01] 0
set part[02].in[01] 1
```
--------------------------------
### Build experimental version with build scripts
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Experimentalversion.html
Build the experimental version using the 'exp' parameter with the provided build scripts. Run these commands from the project root.
```bash
bscripts/build_all_and_install.sh exp
bscripts/build_w64.sh exp
bscripts/build_w32.sh exp
```
--------------------------------
### get ob
Source: https://lcgamboa.github.io/picsimlab_docs/stable/RemoteControlInterface.html
The get command retrieves the value of a specified object or pin.
```APIDOC
## get ob
### Description
Gets the value of an object or pin.
### Method
TCP command
### Endpoint
get ob
### Parameters
- **ob** (string) - Required - The object or pin identifier, e.g., `board.out[00]`, `part[02].in[01]`, `pin[19]`, `pinm[19]`, `apin[25]`, `pinl[13]`.
### Response
#### Success Response
- **Value** (string) - The value of the object or pin.
#### Response Example
```
get board.out[00]
get part[02].in[01]
```
```
--------------------------------
### Initial build for Windows 64-bit
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Windows.html
Clones the PICSIMLab repository and runs the build script for Windows 64-bit targets. Use this on Debian Linux or WSL for the first build.
```bash
git clone https://github.com/lcgamboa/picsimlab.git
cd picsimlab
bscripts/build_w64.sh
```
--------------------------------
### Initial build for Windows 32-bit
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Windows.html
Clones the PICSIMLab repository and runs the build script for Windows 32-bit targets. Use this on Debian Linux or WSL for the first build.
```bash
git clone https://github.com/lcgamboa/picsimlab.git
cd picsimlab
bscripts/build_w32.sh
```
--------------------------------
### First-time build on Debian Linux
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Linux.html
First-time build for Debian Linux and derivatives. Requires a user with sudo permission. Clones the repository, changes into the picsimlab directory, and runs the build-and-install script.
```shell
git clone --depth=1 https://github.com/lcgamboa/picsimlab.git
cd picsimlab
bscripts/build_all_and_install.sh
```
--------------------------------
### cboard_x board implementation: initialization, reset, remote control, and preferences
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Boardcode.html
Board initialization creates gauges and labels, then registers remote control inputs and outputs. The destructor destroys created controls. Reset sets button states and serial status; RefreshStatus updates the status bar with serial baud error percentage. WritePreferences saves the selected microcontroller to preferences.
```cpp
Window1.CreateChild (gauge2);
//label2
label2 = new CLabel ();
label2->SetFOwner (&Window1);
label2->SetName (lxT ("label2_px"));
label2->SetX (12);
label2->SetY (306 - 160);
label2->SetWidth (60);
label2->SetHeight (20);
label2->SetEnable (1);
label2->SetVisible (1);
label2->SetText (lxT ("RB0"));
label2->SetAlign (1);
Window1.CreateChild (label2);
//label3
label3 = new CLabel ();
label3->SetFOwner (&Window1);
label3->SetName (lxT ("label3_px"));
label3->SetX (13);
label3->SetY (357 - 160);
label3->SetWidth (60);
label3->SetHeight (20);
label3->SetEnable (1);
label3->SetVisible (1);
label3->SetText (lxT ("RB1"));
label3->SetAlign (1);
Window1.CreateChild (label3);
}
//Destructor called once on board destruction
cboard_x::~cboard_x(void)
{
//controls destruction
Window1.DestroyChild (gauge1);
Window1.DestroyChild (gauge2);
Window1.DestroyChild (label2);
Window1.DestroyChild (label3);
}
//Reset board status
void
cboard_x::Reset(void)
{
pic_reset (1);
p_BT1 = 1; //set push button in default state (high)
//write button state to pic pin 19 (RD0)
pic_set_pin (19, p_BT1);
//write switch state to pic pin 20 (RD1)
pic_set_pin (20, p_BT2);
//verify serial port state and refresh status bar
#ifndef _WIN_
if (pic.serial[0].serialfd > 0)
#else
if (pic.serial[0].serialfd != INVALID_HANDLE_VALUE)
#endif
Window1.statusbar1.SetField (2, lxT ("Serial: ") +
lxString::FromAscii (SERIALDEVICE) + lxT (":") + itoa (pic.serial[0].serialbaud) + lxT ("(") +
lxString ().Format ("%4.1f", fabs ((100.0 * pic.serial[0].serialexbaud - 100.0 *
pic.serial[0].serialbaud) / pic.serial[0].serialexbaud)) + lxT ("%)"));
else
Window1.statusbar1.SetField (2, lxT ("Serial: ") +
lxString::FromAscii (SERIALDEVICE) + lxT (" (ERROR)"));
if (use_spare)Window5.Reset ();
RegisterRemoteControl ();
}
//Register variables to be controled by remote control
void
cboard_x::RegisterRemoteControl(void)
{
//register inputa
input_ids[I_BD0]->status = &p_BT1;
input_ids[I_SD1]->status = &p_BT2;
input_ids[I_POT1]->status = &pot1;
//register output to be updated on input change
input_ids[I_BD0]->update = &output_ids[O_BD0]->update;
input_ids[I_SD1]->update = &output_ids[O_SD1]->update;
input_ids[I_POT1]->update = &output_ids[O_POT1]->update;
//register outputa
output_ids[O_RB0]->status = &pic.pins[32].oavalue;
output_ids[O_RB1]->status = &pic.pins[33].oavalue;
output_ids[O_LD0]->status = &pic.pins[18].oavalue;
output_ids[O_LD1]->status = &pic.pins[19].oavalue;
}
//Called ever 1s to refresh status
void
cboard_x::RefreshStatus(void)
{
//verify serial port state and refresh status bar
#ifndef _WIN_
if (pic.serial[0].serialfd > 0)
#else
if (pic.serial[0].serialfd != INVALID_HANDLE_VALUE)
#endif
Window1.statusbar1.SetField (2, lxT ("Serial: ") +
lxString::FromAscii (SERIALDEVICE) + lxT (":") + itoa (pic.serial[0].serialbaud) + lxT ("(") +
lxString ().Format ("%4.1f", fabs ((100.0 * pic.serial[0].serialexbaud - 100.0 *
pic.serial[0].serialbaud) / pic.serial[0].serialexbaud)) + lxT ("%)"));
else
Window1.statusbar1.SetField (2, lxT ("Serial: ") +
lxString::FromAscii (SERIALDEVICE) + lxT (" (ERROR)"));
if (use_spare)Window5.Reset ();
RegisterRemoteControl ();
}
//Called to save board preferences in configuration file
void
cboard_x::WritePreferences(void)
{
//write selected microcontroller of board_x to preferences
Window1.saveprefs (lxT ("X_proc"), Proc);
}
```
--------------------------------
### Load binary file with picsimlab_tool
Source: https://lcgamboa.github.io/picsimlab_docs/stable/picsimlabtool.html
Use this command to load a binary file into boards based on ESP32 or STM32 after opening PICSimLab.
```bash
picsimlab_tool loadbin file.bin
```
--------------------------------
### Recompile experimental version with Makefiles
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Experimentalversion.html
Recompile the experimental version using the 'exp' parameter with the provided Makefiles. Use the appropriate Makefile for your target platform.
```makefile
make -j4 exp
make FILE=Makefile.cross -j4 exp
make FILE=Makefile.cross_32 -j4 exp
```
--------------------------------
### Read Analog Output 2
Source: https://lcgamboa.github.io/picsimlab_docs/stable/CommunicationProtocol.html
Sends the command byte 0x32 to select analog output 2, then reads two bytes to form the 16-bit value. The example reads the high and low bytes and combines them into the final value.
```C
Serial_write(0x32);
valorh=Serial_read(0);
valorl=Serial_read(0);
valor=(valorh<<8)|valorl;
```
--------------------------------
### Write Value 230 to Analog Input 1
Source: https://lcgamboa.github.io/picsimlab_docs/stable/CommunicationProtocol.html
Sends the command byte 0x21 to select analog input 1, followed by two bytes representing the 16-bit value. The example writes the value 230 by sending the high byte then the low byte.
```C
Serial_write(0x21);
valor=230;
Serial_write((valor&0xFF00)>>8);
Serial_write(valor&0x00FF);
```
--------------------------------
### help
Source: https://lcgamboa.github.io/picsimlab_docs/stable/RemoteControlInterface.html
The help command displays the list of supported commands in the remote control interface.
```APIDOC
## help
### Description
Shows the list of supported commands in the remote control interface.
### Method
TCP command
### Endpoint
help
### Parameters
None
### Response
#### Success Response
- **List of supported commands** (string) - The list of all available commands.
#### Response Example
```
List of supported commands:
dumpe [a] [s]- dump internal EEPROM memory
dumpf [a] [s]- dump Flash memory
dumpr [a] [s]- dump RAM memory
exit - shutdown PICSimLab
get ob - get object value
help - show this message
info - show actual setup info and objects
loadhex file - load hex file (use full path)
pins - show pins directions and values
pinsl - show pins formated info
quit - exit remote control interface
reset - reset the board
set ob vl - set object with value
sim [cmd] - show simulation status or execute cmd start/stop
sync - wait to syncronize with timer event
version - show PICSimLab version
Ok
```
```
--------------------------------
### PlatformIO configuration for ESP32-gdb debug in VSCode
Source: https://lcgamboa.github.io/picsimlab_docs/stable/ESP32gdbDebug.html
Add these lines to the project's platformio.ini file to enable graphical debug mode in VSCode. It sets a custom upload command for PICSimLab, enables debug build, and defines debug initialization commands. Compile and upload the code to PICSimLab before starting Debug.
```ini
;upload_protocol = esptool
;upload_port = COM7
;upload_port = /dev/tnt2
upload_protocol = custom
upload_command = C:\"Program Files\"\PicsimLab\picsimlab_tool.exe loadbin \"$BUILD_DIR/firmware.bin\"
;upload_command = /usr/bin/picsimlab_tool loadbin \"$BUILD_DIR/firmware.bin\"
build_type = debug
debug_tool = custom
debug_port = localhost:1234
debug_build_flags = -O2 -g
debug_init_break = tbreak main
debug_init_cmds =
define pio_reset_halt_target
monitor system_reset
end
define pio_reset_run_target
monitor system_reset
end
target extended-remote $DEBUG_PORT
$LOAD_CMDS
pio_reset_halt_target
$INIT_BREAK
```
--------------------------------
### Load a PICSimLab Workspace file (.pzw)
Source: https://lcgamboa.github.io/picsimlab_docs/stable/CommandLine.html
Loads a PICSimLab Workspace file (.pzw) by passing the file path as the only argument.
```text
picsimlab file.pzw
```
--------------------------------
### cboard_x preferences and event handlers
Source: https://lcgamboa.github.io/picsimlab_docs/stable/Boardcode.html
Saves board state (switch, clock, potentiometer) to preferences using Window1.saveprefs. Called when configuration file loads preferences; reads X_bt2, X_proc, X_clock, and X_pot1 values. Handles keyboard events for keys '1' and '2' to activate button or toggle switch. Handles mouse button press events over board areas (I_ICSP, I_PWR, I_RST, I_BD0, I_SD1, I_POT1) to load hex, toggle power, reset, activate button, toggle switch, or update potentiometer.
```cpp
//write switch state of board_x to preferences
Window1.saveprefs (lxT ("X_bt2"), lxString ().Format ("%i", p_BT2));
//write microcontroller clock to preferences
Window1.saveprefs (lxT ("X_clock"), lxString ().Format ("%2.1f", Window1.GetClock ()));
//write potentiometer position to preferences
Window1.saveprefs (lxT ("X_pot1"), lxString ().Format ("%i", pot1));
}
```
```cpp
//Called whe configuration file load preferences
void
cboard_x::ReadPreferences(char *name, char *value)
{
//read switch state of board_x of preferences
if (!strcmp (name, "X_bt2"))
{
if (value[0] == '0')
p_BT2 = 0;
else
p_BT2 = 1;
}
//read microcontroller of preferences
if (!strcmp (name, "X_proc"))
{
Proc = value;
}
//read microcontroller clock
if (!strcmp (name, "X_clock"))
{
Window1.SetClock (atof (value));
}
//read potentiometer position
if (!strcmp (name, "X_pot1"))
{
pot1 = atoi (value);
}
}
```
```cpp
//Event on the board
void
cboard_x::EvKeyPress(uint key, uint mask)
{
//if keyboard key 1 is pressed then activate button (state=0)
if (key == '1')
{
p_BT1 = 0;
output_ids[O_BD0]- >update = 1;
}
//if keyboard key 2 is pressed then toggle switch state
if (key == '2')
{
p_BT2 ^= 1;
output_ids[O_SD1]- >update = 1;
}
}
```
```cpp
//Event on the board
void
cboard_x::EvMouseButtonPress(uint button, uint x, uint y, uint state)
{
int i;
//search for the input area which owner the event
for (i = 0; i < inputc; i++)
{
if (((input[i].x1 <= x)&&(input[i].x2 >= x))&&((input[i].y1 <= y)&&
(input[i].y2 >= y)))
{
switch (input[i].id)
{
//if event is over I_ISCP area then load hex file
case I_ICSP:
Window1.menu1_File_LoadHex_EvMenuActive (NULL);
break;
//if event is over I_PWR area then toggle board on/off
case I_PWR:
if (Window1.Get_mcupwr ()) //if on turn off
{
Window1.Set_mcurun (0);
Window1.Set_mcupwr (0);
Reset ();
p_BT1 = 1;
Window1.statusbar1.SetField (0, lxT ("Stoped"));
}
else //if off turn on
{
Window1.Set_mcupwr (1);
Window1.Set_mcurun (1);
Reset ();
Window1.statusbar1.SetField (0, lxT ("Running..."));
}
output_ids[O_LPWR]- >update = 1;
break;
//if event is over I_RST area then turn off and reset
case I_RST:
if (Window1.Get_mcupwr () && pic_reset (- 1))//if powered
{
Window1.Set_mcupwr (0);
Window1.Set_mcurst (1);
}
p_RST = 0;
output_ids[O_RST]- >update = 1;
break;
//if event is over I_D0 area then activate button (state=0)
case I_BD0:
p_BT1 = 0;
output_ids[O_BD0]- >update = 1;
break;
//if event is over I_D1 area then toggle switch state
case I_SD1:
p_BT2 ^= 1;
output_ids[O_SD1]- >update = 1;
break;
case I_POT1:
{
active = 1;
pot1 = (x - input[i].x1)*2.77;
if (pot1 > 199)pot1 = 199;
output_ids[O_POT1]- >update = 1;
}
break;
}
}
}
}
```
```cpp
//Event on the board
void
cboard_x::EvMouseButtonPress(uint button, uint x, uint y, uint state)
{
int i;
//search for the input area which owner the event
for (i = 0; i < inputc; i++)
{
if (((input[i].x1 <= x)&&(input[i].x2 >= x))&&((input[i].y1 <= y)&&
(input[i].y2 >= y)))
{
switch (input[i].id)
{
//if event is over I_ISCP area then load hex file
case I_ICSP:
Window1.menu1_File_LoadHex_EvMenuActive (NULL);
break;
//if event is over I_PWR area then toggle board on/off
case I_PWR:
if (Window1.Get_mcupwr ()) //if on turn off
{
Window1.Set_mcurun (0);
Window1.Set_mcupwr (0);
Reset ();
p_BT1 = 1;
Window1.statusbar1.SetField (0, lxT ("Stoped"));
}
else //if off turn on
{
Window1.Set_mcupwr (1);
Window1.Set_mcurun (1);
Reset ();
Window1.statusbar1.SetField (0, lxT ("Running..."));
}
output_ids[O_LPWR]- >update = 1;
break;
//if event is over I_RST area then turn off and reset
case I_RST:
if (Window1.Get_mcupwr () && pic_reset (- 1))//if powered
{
Window1.Set_mcupwr (0);
Window1.Set_mcurst (1);
}
p_RST = 0;
output_ids[O_RST]- >update = 1;
break;
//if event is over I_D0 area then activate button (state=0)
case I_BD0:
p_BT1 = 0;
output_ids[O_BD0]- >update = 1;
break;
//if event is over I_D1 area then toggle switch state
case I_SD1:
p_BT2 ^= 1;
output_ids[O_SD1]- >update = 1;
break;
case I_POT1:
{
active = 1;
pot1 = (x - input[i].x1)*2.77;
if (pot1 > 199)pot1 = 199;
output_ids[O_POT1]- >update = 1;
}
break;
}
}
}
}
```