B4R Question AppStart shows twice in Logs

aeric

Expert
Licensed User
Longtime User
Is this normal?

Linking everything together...
"C:\\arduino\\hardware\\tools\\avr/bin/avr-gcc" -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin/src.ino.elf" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin\\sketch\\B4RArduino.cpp.o" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin\\sketch\\B4RCore.cpp.o" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin\\sketch\\B4RStream.cpp.o" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin\\sketch\\Scheduler.cpp.o" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin\\sketch\\b4r_main.cpp.o" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin\\sketch\\src.ino.cpp.o" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin/core\\core.a" "-LC:\\B4X\\DEVELO~1\\Button\\Objects\\bin" -lm
"C:\\arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin/src.ino.elf" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin/src.ino.eep"
"C:\\arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin/src.ino.elf" "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin/src.ino.hex"
"C:\\arduino\\hardware\\tools\\avr/bin/avr-size" -A "C:\\B4X\\DEVELO~1\\Button\\Objects\\bin/src.ino.elf"
Sketch uses 6318 bytes (19%) of program storage space. Maximum is 32256 bytes.
Global variables use 292 bytes (14%) of dynamic memory, leaving 1756 bytes for local variables. Maximum is 2048 bytes.
Uploading...
********************* PROGRAM STARTING ****************
AppStart
AppStart
State: 0
State: 1
State: 0
State: 1

Button example:
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Private btn As Pin 'pin for the button
    Private led As Pin 'pin for LED 13 on the Arduino
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    led.Initialize(13, led.MODE_OUTPUT)
    btn.Initialize(btn.A0, btn.MODE_INPUT_PULLUP) 'Using the internal pull up resistor to prevent the pin from floating.
    btn.AddListener("Btn_StateChanged")
End Sub

Sub Btn_StateChanged (State As Boolean)
    Log("State: ", State)
    'state will be False when the button is clicked because of the PULLUP mode.
    led.DigitalWrite(Not(State))
End Sub

B4R version 3.90
Arduino IDE 1.8.19
Arduino UNO R3
Windows 11
 

RJB

Active Member
Licensed User
Longtime User
They quite often restart on 'Connect' so that's probably normal.
You can sometimes get a brownout at start up if the power supply(USB?) is not up to the current need or if the usb lead isn't very good or too long.
I've seen the analogue input used for switches like this but I don't know why as a button input is digital?
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
I can confirm this. Connect means restart. Other reason is a brownout as RJB stated. USB normally has an output of 500 mA which is quite at the minimum. "Heavy" code executions (like encryption, wifi/bt start) often causes these brownouts. An 1 A power supply should be ok.
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Should I bother to fix or ignore it?
Since USB is always supply 500mA then is there any solution?
USB can go over 0.5A, I had used 600-700mA not a problem. USB-C can go over 1A (don't remember)

I don't think your log-problem is about current.

Check if it also happen when using 9600
or adding a delay
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

aeric

Expert
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…