Giter Site home page Giter Site logo

blink example about juniper HOT 16 CLOSED

calebh avatar calebh commented on August 17, 2024
blink example

from juniper.

Comments (16)

pre63 avatar pre63 commented on August 17, 2024 1

@sensor111 I changed the compiler to require setup and loop functions instead of main. So you need to recompile it with the latest commit on master.

from juniper.

calebh avatar calebh commented on August 17, 2024 1

@sensor111 If you aren't able to compile the compiler for some reason I can build it for you. Are you on Windows?

from juniper.

calebh avatar calebh commented on August 17, 2024 1

@sensor111 That issue should be fixed on master now

from juniper.

sensor111 avatar sensor111 commented on August 17, 2024 1

33 heartbeats and counting ;-))

Can we have now solution for esp8266, please? :-)

from juniper.

calebh avatar calebh commented on August 17, 2024 1

Juniper 2.3.0 has been released which fixes this issue.

from juniper.

calebh avatar calebh commented on August 17, 2024

It's possible that there are heap allocations happening which results in fragmented memory and eventually allocation failure. This may occur because closures are heap allocated instead of stack allocated. The solution would be to move the closure type to be stored in the function type, making them stack allocated. Unfortunately I don't have time to update Juniper right now as I've moved on to some new research projects. Ideally the next version of Juniper would include typeclasses as well as the closure function types.

What Arduino are you using?

from juniper.

sensor111 avatar sensor111 commented on August 17, 2024

Thanks @calebh for swift answer.
The arduino is marked as original arduino board model UNO.
I think it was very interesting project and regret you got no time to carry on with it.
Do you know any other project about allowing for functional programing on microcontrolers? Especially ESP 8266 or 32

from juniper.

calebh avatar calebh commented on August 17, 2024

Hmm, I've tested the blink example with the UNO before and it worked for me. It's possible that I did not watch the blinking long enough though. Unfortunately I lost my UNO in a move (along with a bunch of other circuit stuff I had), and the only microcontroller I have right now is a Adafruit Circuit Express.

I am not aware of any other functional languages that are as mature as Juniper that run on systems as small as an Arduino. However there are a couple of other projects that you may be interested in:

  • Circuit Python - however the FAQ explicitly mentions that ESP 8266 and 32 is being dropped as of Circuit Python 4.x
  • Ceu - I talked to the developer of this language at the 2018 SPLASH conference. This is another interesting approach to microcontrollers that feels more imperative than Juniper. Personally I prefer the Juniper FRP style, but your millage may vary.
  • Adel - This is a project from the professor who advised Juniper. It consists of a bunch of very clever C macros that attempt to implement concurrency in a way different from Juniper and Ceu. The approach reminds me of co-routines from the Unity game engine if you're familiar with that.

I can take a look at the closure memory allocation issue this weekend and see if I can get a quick fix for you.

from juniper.

jprivate50 avatar jprivate50 commented on August 17, 2024

Hi Caleb,
thanks for the interesting links.
Have you any success to trace the bug?

from juniper.

pre63 avatar pre63 commented on August 17, 2024

@sensor111 @calebh

I had the same issue with an Arduino Nano 33 BLE. The led stoped blinking after exactly 9 minutes every time I updated the board with juniper code, no matter what the code did, but when using the Arduino's Blink example it was fine, the blinking would go on for hours.

I really wanted to use juniper for programming because I find it so dreadful to write imperative code like c++. Also juniper is quite a nice language with some of my favorite goodies like pattern matching, lambdas, algebraic data types and implicit type inference.

You are already here so you get the point I was really determined not to give up on FP and code a bunch of c++.

Thus, I started removing code form the c++ output in hopes to narrow the code leaking memory and fix it. Since it took 9 minutes testing each hypothesis, I spend a day doing that. But in the end the simplest code without any Juniper generated code had the same problem.

It turns out that by using a scheme like this below with a main function and a while true loop causes the issue.

void main() {
  ...
  while true {
  ...
  }
  ...
}

From what I can tell, the Arduino lib can't determine that you are running code so it puts the device to sleep. To solve this you have to use the setup and loop functions to use the Arduino's features and keep the device on.

In layman terms you must use setup and loop that are called by the Arduino library. Like in every Arduino code example.

void loop() { ... }
void setup() { ... }

Also turn's out that is solves the usb serial being unavailable for the serial monitor or the screen command after upload.

I solved that in PR #3. It's been blinking for over 12 hours. ;)

Cheers!

from juniper.

calebh avatar calebh commented on August 17, 2024

Absolute legend! @sensor111 @jprivate50 would you be able to test the fix before I close this issue?

from juniper.

sensor111 avatar sensor111 commented on August 17, 2024

unfortunately when I tried to compile blink.jun:
Unhandled Exception: System.Exception: Unable to find program entry point. Pleas
e create a function called main.
at Compiler.compileProgram(FSharpList1 program_0, FSharpList1 program_1, FS
harpList1 program_2, FSharpList1 program_3, FSharpList1 program_4) in C:\User s\caleb\Documents\Visual Studio 2015\Projects\Juniper\Juniper\Compiler.fs:line 6 80 at Program.main$cont@55(FSharpList1 sourceFiles, String outputFile, Unit uni
tVar) in C:\Users\caleb\Documents\Visual Studio 2015\Projects\Juniper\Juniper\Pr
ogram.fs:line 89
at Program.main(String[] argv) in C:\Users\caleb\Documents\Visual Studio 2015
\Projects\Juniper\Juniper\Program.fs:line 55

from juniper.

calebh avatar calebh commented on August 17, 2024

Did you recompile the compiler from the latest source from GitHub? Or are you using the prebuilt compiler from the website? The problem is with the compiler, not the blink.jun example

from juniper.

sensor111 avatar sensor111 commented on August 17, 2024

from juniper.

sensor111 avatar sensor111 commented on August 17, 2024

Thanks @calebh - I'm trying to swim by myself ;-)
But I got another problem after I build the compiler and run it:

C:\Users\augug\source\repos\Juniper\Juniper\bin\Debug>juniper.exe -h
Juniper 2.3.0
usage: Juniper.exe -s s1.jun s2.jun ... sn.jun -o main.cpp
options:
-s, --source: The .jun Juniper source files to compile
-o, --output: The file in which the compiled C++ is written
-h, --help: View this help message

C:\Users\augug\source\repos\Juniper\Juniper\bin\Debug>juniper.exe -s blink.jun -o blinkjuniper

Unhandled Exception: System.ArgumentException: The input must be non-negative.
count = -1
Parameter name: count
at Microsoft.FSharp.Core.StringModule.Replicate(Int32 count, String str) in F:\workspace_work\1\s\src\fsharp\FSharp.Core\string.fs:line 79
at Compiler.output(String str) in C:\Users\augug\Source\Repos\Juniper\Juniper\Compiler.fs:line 23
at Compiler.compileProgram(FSharpList1 program_0, FSharpList1 program_1, FSharpList1 program_2, FSharpList1 program_3, FSharpList`1 program_4) in C:\Users\augug\Source\Repos\Juniper\Juniper\Compiler.fs:line 699
at Program.main(String[] argv) in C:\Users\augug\Source\Repos\Juniper\Juniper\Program.fs:line 89

from juniper.

calebh avatar calebh commented on August 17, 2024

@sensor111 There are some examples of C++ library wrappers in the wrappers directory if you'd like to write your own wrapper for esp8266. https://github.com/calebh/Juniper/tree/master/Juniper/wrappers

from juniper.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.