# Generating sin wave output values to serial port

**URL:** <https://discourse.processing.org/t/generating-sin-wave-output-values-to-serial-port/39297>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [October 16, 2022, 1:11pm UTC](https://discourse.processing.org/t/generating-sin-wave-output-values-to-serial-port/39297 "2022-10-16T13:11:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.processing.org/u/andy)\
**Post date:** [October 16, 2022, 1:11pm UTC](https://discourse.processing.org/t/generating-sin-wave-output-values-to-serial-port/39297/1 "2022-10-16T13:11:08Z")

</div>

Good evening to you all.

Forgive me, my first day with processing on windows and looking for some pointers to get me started.

I have 8 bit DtoA converters connected to my serial port that take an 8 bit address and 8 bit values to set the analog voltages.

First of all, is it possible using processing to send out sin wave values to the DtoA’s.

The baud rate is 19600 and the format is very basic address,value ( both are bytes )

I am looking at very slowly like three seconds per cycle going from 0 to 255 also having a control over the frequency, amplitude and phase of the two outputs. Phase being the difference in time from one wave to the other, ie the second wave value is at 255 when the first is at 128 but in a variable way called phase\_shift.

Thank you.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 16, 2022, 1:29pm UTC](https://discourse.processing.org/t/generating-sin-wave-output-values-to-serial-port/39297/2 "2022-10-16T13:29:23Z")

</div>

Hi and welcome

Yes you can communicate with Arduino via processing serial library

> **[Serial / Libraries](https://processing.org/reference/libraries/serial/index.html)**
>
> Send data between Processing and external hardware through serial communication (RS-232).

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 17, 2022, 12:04pm UTC](https://discourse.processing.org/t/generating-sin-wave-output-values-to-serial-port/39297/3 "2022-10-17T12:04:30Z")

</div>

Hi Sir  
Before you start to send sin or whatever you want you may need to start by learning more about processing and Arduino browsing YouTube and google you find more examples how to start

[![](https://img.youtube.com/vi/yOMglntmmnA/maxresdefault.jpg "Arduino Tutorial 06: Processing") ](https://www.youtube.com/watch?v=yOMglntmmnA)

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.processing.org/u/andy)\
**Post date:** [October 17, 2022, 10:58pm UTC](https://discourse.processing.org/t/generating-sin-wave-output-values-to-serial-port/39297/4 "2022-10-17T22:58:54Z")

</div>

Using serial data isn’t something new for me, been using MCUs for 30 years. Just the Sin functions and processing are new.

Looking at processing as a modern alternative to using vb or Delphi.

Asking for guidance to determine if I spend more time with processing which has good cross platform support.

I did have a look at the video, it is useful to perform communication testing between processing and the Arduino so thanks for sharing it. Interesting comment that the Arduino editor is made with processing. One of the things I was wondering was about adding a menu to a project.

I actually use my own developed boards based on atmega128s that do pretty much the same task as the Arduino.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [October 18, 2022, 4:58am UTC](https://discourse.processing.org/t/generating-sin-wave-output-values-to-serial-port/39297/5 "2022-10-18T04:58:29Z")

</div>

> One of the things I was wondering was about adding a menu to a project.

The following source code will place a menuBar in the default Processing window. This one uses .awt component. Can also be done with a Swing component.

```auto
import java.awt.*;
import java.awt.event.*;

java.awt.Frame frame;

void setup() {
  size(400, 400);
  frame = ((processing.awt.PSurfaceAWT.SmoothCanvas) ((processing.awt.PSurfaceAWT)surface).getNative()).getFrame();

  MenuBar menubar = new MenuBar();
  Menu menu = new Menu("File");
  MenuItem open = new MenuItem("Open");
  MenuItem save = new MenuItem("Save");
  menu.add(open);
  menu.add(save);
  menubar.add(menu);
  frame.setMenuBar(menubar);

  open.addActionListener(new ActionListener() {
    void actionPerformed(ActionEvent evnt) {
      println("open selected");
    }
  }
  );

  save.addActionListener(new ActionListener() {
    void actionPerformed(ActionEvent evnt) {
      println("save selected");
    }
  }
  );
}

void draw() {
  circle(100, 100, 100);
}

```

---

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.processing.org/u/andy)\
**Post date:** [October 18, 2022, 4:48pm UTC](https://discourse.processing.org/t/generating-sin-wave-output-values-to-serial-port/39297/6 "2022-10-18T16:48:36Z")

</div>

Thank you Svan, that made it simple.
